Skip to content

Instantly share code, notes, and snippets.

@elizabethlin

elizabethlin/pytest_myplugin.py Secret

Last active Dec 17, 2015
Embed
What would you like to do?
now we're getting: test_example.py:34: TestExample.test_one[std] FAILED test_example.py:38: TestExample.test_two[std] FAILED test_example.py:34: TestExample.test_one[typeA] FAILED test_example.py:38: TestExample.test_two[typeA] FAILED test_example.py:34: TestExample.test_one[typeB] FAILED test_example.py:38: TestExample.test_two[typeB] FAILED te…
import pytest
def pytest_generate_tests(metafunc):
if 'generatedfix' in metafunc.fixturenames:
# I get the params from a yaml file, simplifying atm
metafunc.parametrize('generatedfix', ['typeA', 'typeB'], indirect=True,
scope='session')
@pytest.fixture(scope='session')
def generatedfix(request):
if request.param == 'typeA':
return 'typeA'
elif request.param == 'typeB':
return 'typeB'
import pytest
import pytest_myplugin
pytest_plugins = ['pytest_myplugin']
def pytest_generate_tests(metafunc):
if 'fixA' in metafunc.fixturenames:
# would grab the yaml file info here
values = ['typeA', 'typeB']
values.insert(0, 'std')
metafunc.parametrize('fixA', values, indirect=True, scope='session')
@pytest.fixture(scope='session')
def fixA(request):
if request.param == 'std':
return request.getfuncargvalue("std")
else:
return virt(pytest_myplugin.generatedfix(request))
@pytest.fixture(scope='session')
def std(request):
return "std"
@pytest.fixture(scope='session')
def virt(request, generatedfix):
return "virt-{0}".format(generatedfix)
class TestExample(object):
def test_one(self, fixA):
print fixA
assert(0)
def test_two(self, fixA):
print fixA
assert(0)
def test_three(self, std):
print std
assert(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment