xunit-style functions and methods are invoked by autouse fixtures
Fix #3094, Fix #517
This commit is contained in:
@@ -240,9 +240,6 @@ class TestClass(object):
|
||||
assert result.ret == EXIT_NOTESTSCOLLECTED
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
"ignore:usage of Generator.Function is deprecated, please use pytest.Function instead"
|
||||
)
|
||||
class TestFunction(object):
|
||||
def test_getmodulecollector(self, testdir):
|
||||
item = testdir.getitem("def test_func(): pass")
|
||||
|
||||
@@ -1226,6 +1226,45 @@ class TestFixtureUsages(object):
|
||||
values = reprec.getcalls("pytest_runtest_call")[0].item.module.values
|
||||
assert values == [1, 2, 10, 20]
|
||||
|
||||
def test_setup_functions_as_fixtures(self, testdir):
|
||||
"""Ensure setup_* methods obey fixture scope rules (#517, #3094)."""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
DB_INITIALIZED = None
|
||||
|
||||
@pytest.yield_fixture(scope="session", autouse=True)
|
||||
def db():
|
||||
global DB_INITIALIZED
|
||||
DB_INITIALIZED = True
|
||||
yield
|
||||
DB_INITIALIZED = False
|
||||
|
||||
def setup_module():
|
||||
assert DB_INITIALIZED
|
||||
|
||||
def teardown_module():
|
||||
assert DB_INITIALIZED
|
||||
|
||||
class TestClass(object):
|
||||
|
||||
def setup_method(self, method):
|
||||
assert DB_INITIALIZED
|
||||
|
||||
def teardown_method(self, method):
|
||||
assert DB_INITIALIZED
|
||||
|
||||
def test_printer_1(self):
|
||||
pass
|
||||
|
||||
def test_printer_2(self):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["* 2 passed in *"])
|
||||
|
||||
|
||||
class TestFixtureManagerParseFactories(object):
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user