Created
October 6, 2015 01:38
-
-
Save poros/4ce8cedd0c2311b3d7fd to your computer and use it in GitHub Desktop.
Parametrized pytest testcase with dictionary of parameters and human readable testcase names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_params = { | |
'empty_line': ('', {}), | |
'get_ok': ('GET 200', {'request': 'GET', 'status': '200'}), | |
'get_not_found': ('GET 404', {'request': 'GET', 'status': '404'}), | |
} | |
@pytest.mark.parametrize('line,expected', test_params.values(), ids=test_params.keys()) | |
def test_decode(self, line, expected): | |
assert Decoder().decode(line) == expected | |
Thank you!!
That was very helpful! saved me considerable amount of time.!
Thank you! Very helpful and concise :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
In case someone copy&pastes this solution in Python 3.x, you have to wrap
test_params.keys()
withlist
becauseids=list(test_params.keys())
source: https://stackoverflow.com/questions/17322668/typeerror-dict-keys-object-does-not-support-indexing