Skip to content

Instantly share code, notes, and snippets.

@mrzechonek
Created January 3, 2020 21:20
Show Gist options
  • Save mrzechonek/4fb39304f7c24801cc419a9297f986f9 to your computer and use it in GitHub Desktop.
Save mrzechonek/4fb39304f7c24801cc419a9297f986f9 to your computer and use it in GitHub Desktop.
import pytest
from typing import NamedTuple
class SomeFixture(NamedTuple):
first_option: bool = False
second_option: bool = True
@pytest.fixture
def some_fixture(request):
marker = request.node.get_closest_marker('some_fixture')
return SomeFixture(*marker.args, **marker.kwargs) if marker else SomeFixture()
def test_default_options(some_fixture):
assert some_fixture.first_option is False
assert some_fixture.second_option is True
@pytest.mark.some_fixture(first_option=True, second_option=False)
def test_custom_options(some_fixture):
assert some_fixture.first_option is True
assert some_fixture.second_option is False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment