Created
August 25, 2022 16:40
-
-
Save sebastianschramm/d0faad29b68a7b8d124ea77ccabd5e75 to your computer and use it in GitHub Desktop.
How to parametrize fixtures in 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
import json | |
import pytest | |
@pytest.fixture | |
def min_dict(): | |
return {"name": "foo"} | |
@pytest.fixture | |
def full_dict(): | |
return {"name": "bar", "country": "DE"} | |
@pytest.fixture(params=["min_dict", "full_dict"]) | |
def test_dict(request): | |
return request.getfixturevalue(request.param) | |
@pytest.mark.parametrize("indentation, expected_linebreak", [(4, "\n"), (None, "")]) | |
def test_instantiation(expected_linebreak, indentation, test_dict): | |
assert expected_linebreak in json.dumps(test_dict, indent=indentation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies: python3.9, pytest==7.1.2