Skip to content

Instantly share code, notes, and snippets.

@chrisguidry
Last active July 7, 2016 14:10
Show Gist options
  • Save chrisguidry/51fbee52f62ff88bb2cde8db01840ad6 to your computer and use it in GitHub Desktop.
Save chrisguidry/51fbee52f62ff88bb2cde8db01840ad6 to your computer and use it in GitHub Desktop.
How do I do this correctly with pytest?
@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
@chrisguidry
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment