Reputation: 5417
Is it possible to pass fixtures to pytest generative tests?
import py.test
@py.test.fixture(scope="module")
def fixture():
return True
def test_1(fixture):
def checker(datum):
assert datum == fixture
for i in [True, True, True]:
# Does not work.
yield checker, i
# Does work.
#checker(i)
The above code produces
> for i, x in enumerate(self.obj()):
name, call, args = self.getcallargs(x)
E TypeError: test_1() takes exactly 1 argument (0 given)
We use py.test 2.3.5 from Debian.
Upvotes: 1
Views: 459
Reputation: 3890
Don't know exactly what yield
inside test definition suppose to do.
There is yield
in fixtures Fixture functions using “yield” / context manager integration that works not as one expects at first.
If you want to iterate the same test over a sequence of fixtures you probably need Parametrizing a fixture
Upvotes: 3