Parameterizing test (#2073)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alex Kahan · committed by David Lord · parent a4ed3d2 · Browse files · 1 file·+9 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+9 added−15 removed
- tests:+9 added−15 removed
Provenance
- Commit
2647fc7- Tree
bc444c0- Author
Alex Kahan <alex@zerofox.com>- Committer
David Lord <davidism@gmail.com>- Parent
a4ed3d2
1 file changed+9 added−15 removed
modified:tests/test_helpers.py+9 added-15 removed
111 unmodified lines112 out.seek(0)113 rv = flask.json.load(out)114 assert rv == test_data115 116+ @pytest.mark.parametrize('test_value', [0, -1, 1, 23, 3.14, 's', "longer string", True, False, None])116- def test_jsonify_basic_types(self):117+ def test_jsonify_basic_types(self, test_value):118 """Test jsonify with basic types."""118- # Should be able to use pytest parametrize on this, but I couldn't119- # figure out the correct syntax120- # https://pytest.org/latest/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions121- test_data = (0, 1, 23, 3.14, 's', "longer string", True, False,)119 app = flask.Flask(__name__)120 c = app.test_client()124- for i, d in enumerate(test_data):125- url = '/jsonify_basic_types{0}'.format(i)126- app.add_url_rule(url, str(i), lambda x=d: flask.jsonify(x))127- rv = c.get(url)128- assert rv.mimetype == 'application/json'129- assert flask.json.loads(rv.data) == d121 122+ url = '/jsonify_basic_types'123+ app.add_url_rule(url, url, lambda x=test_value: flask.jsonify(x))124+ rv = c.get(url)125+ assert rv.mimetype == 'application/json'126+ assert flask.json.loads(rv.data) == test_value127+128 def test_jsonify_dicts(self):129 """Test jsonify with dicts and kwargs unpacking."""130 d = dict(131 a=0, b=23, c=3.14, d='t', e='Hi', f=True, g=False,34 unmodified lines166 assert flask.json.loads(rv.data) == l167 168 def test_jsonify_date_types(self):169 """Test jsonify with datetime.date and datetime.datetime types."""173-170 test_dates = (171 datetime.datetime(1973, 3, 11, 6, 30, 45),172 datetime.date(1975, 1, 5)173 )178-174 app = flask.Flask(__name__)175 c = app.test_client()176 177 for i, d in enumerate(test_dates):5 unmodified lines183 184 def test_jsonify_uuid_types(self):185 """Test jsonify with uuid.UUID types"""186 192- test_uuid = uuid.UUID(bytes=b'\xDE\xAD\xBE\xEF'*4)193-187+ test_uuid = uuid.UUID(bytes=b'\xDE\xAD\xBE\xEF' * 4)188 app = flask.Flask(__name__)189 url = '/uuid_test'190 app.add_url_rule(url, url, lambda: flask.jsonify(x=test_uuid))191 688 unmodified lines