Skip to content

Instantly share code, notes, and snippets.

@sebastianschramm
Created August 25, 2022 16:40
Show Gist options
  • Save sebastianschramm/d0faad29b68a7b8d124ea77ccabd5e75 to your computer and use it in GitHub Desktop.
Save sebastianschramm/d0faad29b68a7b8d124ea77ccabd5e75 to your computer and use it in GitHub Desktop.
How to parametrize fixtures in pytest
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)
@sebastianschramm
Copy link
Author

dependencies: python3.9, pytest==7.1.2

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