testing: fix some tests to be more realistic
Perform the operations in the order and context in which they can legally occur.
This commit is contained in:
parent
c83d030028
commit
637300d13d
|
@ -130,7 +130,8 @@ class TestFillFixtures:
|
|||
pytester.copy_example()
|
||||
item = pytester.getitem(Path("test_funcarg_basic.py"))
|
||||
assert isinstance(item, Function)
|
||||
item._request._fillfixtures()
|
||||
# Execute's item's setup, which fills fixtures.
|
||||
item.session._setupstate.prepare(item)
|
||||
del item.funcargs["request"]
|
||||
assert len(get_public_names(item.funcargs)) == 2
|
||||
assert item.funcargs["some"] == "test_func"
|
||||
|
@ -809,18 +810,25 @@ class TestRequestBasic:
|
|||
item = pytester.getitem(
|
||||
"""
|
||||
import pytest
|
||||
values = [2]
|
||||
|
||||
@pytest.fixture
|
||||
def something(request): return 1
|
||||
def something(request):
|
||||
return 1
|
||||
|
||||
values = [2]
|
||||
@pytest.fixture
|
||||
def other(request):
|
||||
return values.pop()
|
||||
|
||||
def test_func(something): pass
|
||||
"""
|
||||
)
|
||||
assert isinstance(item, Function)
|
||||
req = item._request
|
||||
|
||||
# Execute item's setup.
|
||||
item.session._setupstate.prepare(item)
|
||||
|
||||
with pytest.raises(pytest.FixtureLookupError):
|
||||
req.getfixturevalue("notexists")
|
||||
val = req.getfixturevalue("something")
|
||||
|
@ -831,7 +839,6 @@ class TestRequestBasic:
|
|||
assert val2 == 2
|
||||
val2 = req.getfixturevalue("other") # see about caching
|
||||
assert val2 == 2
|
||||
item._request._fillfixtures()
|
||||
assert item.funcargs["something"] == 1
|
||||
assert len(get_public_names(item.funcargs)) == 2
|
||||
assert "request" in item.funcargs
|
||||
|
|
|
@ -104,13 +104,14 @@ class TestSetupState:
|
|||
module_teardown.append("fin_module")
|
||||
|
||||
item = pytester.getitem("def test_func(): pass")
|
||||
mod = item.listchain()[-2]
|
||||
ss = item.session._setupstate
|
||||
ss.addfinalizer(fin_module, item.listchain()[-2])
|
||||
ss.addfinalizer(fin_func, item)
|
||||
ss.prepare(item)
|
||||
ss.addfinalizer(fin_module, mod)
|
||||
ss.addfinalizer(fin_func, item)
|
||||
with pytest.raises(Exception, match="oops1"):
|
||||
ss.teardown_exact(None)
|
||||
assert module_teardown
|
||||
assert module_teardown == ["fin_module"]
|
||||
|
||||
|
||||
class BaseFunctionalTests:
|
||||
|
|
Loading…
Reference in New Issue