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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user