Last active
July 7, 2016 14:10
-
-
Save chrisguidry/51fbee52f62ff88bb2cde8db01840ad6 to your computer and use it in GitHub Desktop.
How do I do this correctly with pytest?
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
@pytest.fixture | |
def error_condition_one(some_fixture): | |
...set up one type of error condition... | |
...for example, an error response with httpretty, or a mock... | |
@pytest.fixture | |
def error_condition_two(another_fixture): | |
...set up a different error condition... | |
@pytest.mark.parametrize('error_condition', [ | |
error_condition_one, | |
error_condition_two | |
]) | |
def test_handles_error_conditions_uniformly(error_condition, caplog): | |
"""Any error conditions should return None and log a warning""" | |
assert the_function_under_test() is None | |
assert 'bad things happened' in caplog.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The basic idea here is that I want to verify that
the_function_under_test
behaves in a specific way under a variety of preconditions. I'd like to capture those preconditions as fixtures.