You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across the following situation which I have simplified into the example below.
If a Module Fixture depends on a Function Fixture and a test depends on both, but has (Function Fixture, Module Fixture) in its argument order, the Module Fixture is reduced to run as a Function Fixture
Tested on py.test 2.6.4
#!python
import pytest
class SomeClass(object): pass
@pytest.fixture
def function_fixture(request):
def fin():
print "I am a function finalizer"
request.addfinalizer(fin)
print "\n"
print "I am a function fixture"
return SomeClass()
@pytest.fixture(scope="module")
def module_fixture(request, function_fixture):
def fin():
print "I am a module finalizer"
request.addfinalizer(fin)
print "I am a module fixture"
return SomeClass()
def test_one(function_fixture, module_fixture):
print "Test One"
print "Module Fixture: {}".format(module_fixture)
def test_two(function_fixture, module_fixture):
print "Test Two"
print "Module Fixture: {}".format(module_fixture)
Output: (-s --verbose)
test.py::test_one
I am a function fixture
I am a module fixture
Test One
Module Fixture: <test.SomeClass object at 0x102f037d0>
PASSEDI am a module finalizer
I am a function finalizer
test.py::test_two
I am a function fixture
I am a module fixture
Test Two
Module Fixture: <test.SomeClass object at 0x102f48fd0>
PASSEDI am a module finalizer
I am a function finalizer
Notice that the Module Fixture code has executed twice and the addresses of the SomeClass instances are different.
If module_fixture did not depend on function_fixture, the module_fixture would run only once. Test function calling (module_fixture, function_fixture) results in a ScopeMismatchError.
Originally reported by: Praveen Shirali (BitBucket: praveenshirali, GitHub: praveenshirali)
I came across the following situation which I have simplified into the example below.
If a
Module Fixture
depends on aFunction Fixture
and a test depends on both, but has(Function Fixture, Module Fixture)
in its argument order, theModule Fixture
is reduced to run as aFunction Fixture
Tested on py.test 2.6.4
Output: (-s --verbose)
Notice that the Module Fixture code has executed twice and the addresses of the SomeClass instances are different.
If
module_fixture
did not depend onfunction_fixture
, themodule_fixture
would run only once. Test function calling(module_fixture, function_fixture)
results in aScopeMismatchError
.The text was updated successfully, but these errors were encountered: