Skip to content

Instantly share code, notes, and snippets.

@edofic
Created May 15, 2017 06:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edofic/aeab43fab80d315932b32df0ec862920 to your computer and use it in GitHub Desktop.
Save edofic/aeab43fab80d315932b32df0ec862920 to your computer and use it in GitHub Desktop.
Indirect parametrization in pytest
import pytest
@pytest.fixture()
def user(request):
user = 'mock user'
if hasattr(request, 'param'):
user += ': {}'.format(request.param)
return user
@pytest.mark.parametrize('user', ('foo',), indirect=True)
def test_foo(user):
assert user == 'mock user: foo'
@pytest.mark.parametrize('user', ('bar',), indirect=True)
def test_bar(user):
assert user == 'mock user: bar'
def test_default(user):
assert user == 'mock user'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment