2013-08-14 19:58:59 +08:00
|
|
|
"""Tests for fixtures with different scoping."""
|
|
|
|
import py.code
|
|
|
|
|
|
|
|
|
|
|
|
def test_fixture_finalizer(testdir):
|
|
|
|
testdir.makeconftest("""
|
|
|
|
import pytest
|
2013-08-15 17:52:55 +08:00
|
|
|
import sys
|
2013-08-14 19:58:59 +08:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def browser(request):
|
|
|
|
|
|
|
|
def finalize():
|
2013-08-15 17:52:55 +08:00
|
|
|
sys.stdout.write('Finalized')
|
2013-08-14 19:58:59 +08:00
|
|
|
request.addfinalizer(finalize)
|
|
|
|
return {}
|
|
|
|
""")
|
|
|
|
b = testdir.mkdir("subdir")
|
|
|
|
b.join("test_overriden_fixture_finalizer.py").write(py.code.Source("""
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def browser(browser):
|
|
|
|
browser['visited'] = True
|
|
|
|
return browser
|
|
|
|
|
|
|
|
def test_browser(browser):
|
|
|
|
assert browser['visited'] is True
|
|
|
|
"""))
|
|
|
|
reprec = testdir.runpytest("-s")
|
|
|
|
for test in ['test_browser']:
|
2013-09-27 18:28:34 +08:00
|
|
|
reprec.stdout.fnmatch_lines('*Finalized*')
|