re-introduce the old 2.2.4 FuncargRequest implementation as it is a better
base for implementing the new funcarg/setup api. Also Un-optimize funcargnames discovery for now.
This commit is contained in:
@@ -277,14 +277,18 @@ class TestFunction:
|
||||
def test_function_equality(self, testdir, tmpdir):
|
||||
config = testdir.parseconfigure()
|
||||
session = testdir.Session(config)
|
||||
def func1():
|
||||
pass
|
||||
def func2():
|
||||
pass
|
||||
f1 = pytest.Function(name="name", config=config,
|
||||
args=(1,), callobj=isinstance, session=session)
|
||||
args=(1,), callobj=func1, session=session)
|
||||
f2 = pytest.Function(name="name",config=config,
|
||||
args=(1,), callobj=py.builtin.callable, session=session)
|
||||
args=(1,), callobj=func2, session=session)
|
||||
assert not f1 == f2
|
||||
assert f1 != f2
|
||||
f3 = pytest.Function(name="name", config=config,
|
||||
args=(1,2), callobj=py.builtin.callable, session=session)
|
||||
args=(1,2), callobj=func2, session=session)
|
||||
assert not f3 == f2
|
||||
assert f3 != f2
|
||||
|
||||
@@ -292,7 +296,7 @@ class TestFunction:
|
||||
assert f3 != f1
|
||||
|
||||
f1_b = pytest.Function(name="name", config=config,
|
||||
args=(1,), callobj=isinstance, session=session)
|
||||
args=(1,), callobj=func1, session=session)
|
||||
assert f1 == f1_b
|
||||
assert not f1 != f1_b
|
||||
|
||||
@@ -307,10 +311,12 @@ class TestFunction:
|
||||
funcargs = {}
|
||||
id = "world"
|
||||
session = testdir.Session(config)
|
||||
def func():
|
||||
pass
|
||||
f5 = pytest.Function(name="name", config=config,
|
||||
callspec=callspec1, callobj=isinstance, session=session)
|
||||
callspec=callspec1, callobj=func, session=session)
|
||||
f5b = pytest.Function(name="name", config=config,
|
||||
callspec=callspec2, callobj=isinstance, session=session)
|
||||
callspec=callspec2, callobj=func, session=session)
|
||||
assert f5 != f5b
|
||||
assert not (f5 == f5b)
|
||||
|
||||
@@ -549,7 +555,7 @@ class TestFillFuncArgs:
|
||||
return 42
|
||||
""")
|
||||
item = testdir.getitem("def test_func(some): pass")
|
||||
exc = pytest.raises(funcargs.OldFuncargRequest.LookupError,
|
||||
exc = pytest.raises(funcargs.FuncargRequest.LookupError,
|
||||
"funcargs.fillfuncargs(item)")
|
||||
s = str(exc.value)
|
||||
assert s.find("xyzsomething") != -1
|
||||
@@ -624,7 +630,7 @@ class TestRequest:
|
||||
def pytest_funcarg__something(request): pass
|
||||
def test_func(something): pass
|
||||
""")
|
||||
req = funcargs.OldFuncargRequest(item)
|
||||
req = funcargs.FuncargRequest(item)
|
||||
assert req.function == item.obj
|
||||
assert req.keywords is item.keywords
|
||||
assert hasattr(req.module, 'test_func')
|
||||
@@ -639,7 +645,7 @@ class TestRequest:
|
||||
def test_func(self, something):
|
||||
pass
|
||||
""")
|
||||
req = funcargs.OldFuncargRequest(item)
|
||||
req = funcargs.FuncargRequest(item)
|
||||
assert req.cls.__name__ == "TestB"
|
||||
assert req.instance.__class__ == req.cls
|
||||
|
||||
@@ -653,7 +659,7 @@ class TestRequest:
|
||||
""")
|
||||
item1, = testdir.genitems([modcol])
|
||||
assert item1.name == "test_method"
|
||||
name2factory = funcargs.OldFuncargRequest(item1)._name2factory
|
||||
name2factory = funcargs.FuncargRequest(item1)._name2factory
|
||||
assert len(name2factory) == 1
|
||||
assert name2factory[0].__name__ == "pytest_funcarg__something"
|
||||
|
||||
@@ -668,7 +674,7 @@ class TestRequest:
|
||||
def test_func(something):
|
||||
assert something == 2
|
||||
""")
|
||||
req = funcargs.OldFuncargRequest(item)
|
||||
req = funcargs.FuncargRequest(item)
|
||||
val = req.getfuncargvalue("something")
|
||||
assert val == 2
|
||||
|
||||
@@ -680,7 +686,7 @@ class TestRequest:
|
||||
return l.pop()
|
||||
def test_func(something): pass
|
||||
""")
|
||||
req = funcargs.OldFuncargRequest(item)
|
||||
req = funcargs.FuncargRequest(item)
|
||||
pytest.raises(req.LookupError, req.getfuncargvalue, "notexists")
|
||||
val = req.getfuncargvalue("something")
|
||||
assert val == 1
|
||||
@@ -691,7 +697,8 @@ class TestRequest:
|
||||
val2 = req.getfuncargvalue("other") # see about caching
|
||||
assert val2 == 2
|
||||
pytest._fillfuncargs(item)
|
||||
assert item.funcargs == {'something': 1, "other": 2}
|
||||
assert item.funcargs == {'something': 1}
|
||||
#assert item.funcargs == {'something': 1, "other": 2}
|
||||
|
||||
def test_request_addfinalizer(self, testdir):
|
||||
item = testdir.getitem("""
|
||||
@@ -728,7 +735,7 @@ class TestRequest:
|
||||
def test_request_getmodulepath(self, testdir):
|
||||
modcol = testdir.getmodulecol("def test_somefunc(): pass")
|
||||
item, = testdir.genitems([modcol])
|
||||
req = funcargs.OldFuncargRequest(item)
|
||||
req = funcargs.FuncargRequest(item)
|
||||
assert req.fspath == modcol.fspath
|
||||
|
||||
def test_applymarker(testdir):
|
||||
@@ -739,7 +746,7 @@ def test_applymarker(testdir):
|
||||
def test_func2(self, something):
|
||||
pass
|
||||
""")
|
||||
req1 = funcargs.OldFuncargRequest(item1)
|
||||
req1 = funcargs.FuncargRequest(item1)
|
||||
assert 'xfail' not in item1.keywords
|
||||
req1.applymarker(pytest.mark.xfail)
|
||||
assert 'xfail' in item1.keywords
|
||||
@@ -757,7 +764,7 @@ class TestRequestCachedSetup:
|
||||
def test_func2(self, something):
|
||||
pass
|
||||
""")
|
||||
req1 = funcargs.OldFuncargRequest(item1)
|
||||
req1 = funcargs.FuncargRequest(item1)
|
||||
l = ["hello"]
|
||||
def setup():
|
||||
return l.pop()
|
||||
@@ -766,7 +773,7 @@ class TestRequestCachedSetup:
|
||||
assert ret1 == "hello"
|
||||
ret1b = req1.cached_setup(setup)
|
||||
assert ret1 == ret1b
|
||||
req2 = funcargs.OldFuncargRequest(item2)
|
||||
req2 = funcargs.FuncargRequest(item2)
|
||||
ret2 = req2.cached_setup(setup)
|
||||
assert ret2 == ret1
|
||||
|
||||
@@ -782,7 +789,7 @@ class TestRequestCachedSetup:
|
||||
def test_func2b(self, something):
|
||||
pass
|
||||
""")
|
||||
req1 = funcargs.OldFuncargRequest(item2)
|
||||
req1 = funcargs.FuncargRequest(item2)
|
||||
l = ["hello2", "hello"]
|
||||
def setup():
|
||||
return l.pop()
|
||||
@@ -791,22 +798,22 @@ class TestRequestCachedSetup:
|
||||
# automatically turn "class" to "module" scope
|
||||
ret1 = req1.cached_setup(setup, scope="class")
|
||||
assert ret1 == "hello"
|
||||
req2 = funcargs.OldFuncargRequest(item2)
|
||||
req2 = funcargs.FuncargRequest(item2)
|
||||
ret2 = req2.cached_setup(setup, scope="class")
|
||||
assert ret2 == "hello"
|
||||
|
||||
req3 = funcargs.OldFuncargRequest(item3)
|
||||
req3 = funcargs.FuncargRequest(item3)
|
||||
ret3a = req3.cached_setup(setup, scope="class")
|
||||
ret3b = req3.cached_setup(setup, scope="class")
|
||||
assert ret3a == "hello2"
|
||||
assert ret3b == "hello2"
|
||||
req4 = funcargs.OldFuncargRequest(item4)
|
||||
req4 = funcargs.FuncargRequest(item4)
|
||||
ret4 = req4.cached_setup(setup, scope="class")
|
||||
assert ret4 == ret3a
|
||||
|
||||
def test_request_cachedsetup_extrakey(self, testdir):
|
||||
item1 = testdir.getitem("def test_func(): pass")
|
||||
req1 = funcargs.OldFuncargRequest(item1)
|
||||
req1 = funcargs.FuncargRequest(item1)
|
||||
l = ["hello", "world"]
|
||||
def setup():
|
||||
return l.pop()
|
||||
@@ -821,7 +828,7 @@ class TestRequestCachedSetup:
|
||||
|
||||
def test_request_cachedsetup_cache_deletion(self, testdir):
|
||||
item1 = testdir.getitem("def test_func(): pass")
|
||||
req1 = funcargs.OldFuncargRequest(item1)
|
||||
req1 = funcargs.FuncargRequest(item1)
|
||||
l = []
|
||||
def setup():
|
||||
l.append("setup")
|
||||
@@ -1093,9 +1100,9 @@ class TestMetafuncFunctional:
|
||||
def pytest_generate_tests(metafunc):
|
||||
metafunc.addcall(param=metafunc)
|
||||
|
||||
def pytest_funcarg__metafunc(item):
|
||||
assert item._genid == "0"
|
||||
return item.param
|
||||
def pytest_funcarg__metafunc(request):
|
||||
assert request._pyfuncitem._genid == "0"
|
||||
return request.param
|
||||
|
||||
def test_function(metafunc, pytestconfig):
|
||||
assert metafunc.config == pytestconfig
|
||||
@@ -1591,6 +1598,7 @@ def test_issue117_sessionscopeteardown(testdir):
|
||||
])
|
||||
|
||||
class TestRequestAPI:
|
||||
@pytest.mark.xfail(reason="reverted refactoring")
|
||||
def test_addfinalizer_cachedsetup_getfuncargvalue(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
l = []
|
||||
@@ -1615,10 +1623,11 @@ class TestRequestAPI:
|
||||
"*2 passed*",
|
||||
])
|
||||
|
||||
@pytest.mark.xfail(reason="consider item's funcarg access and error conditions")
|
||||
def test_runtest_setup_sees_filled_funcargs(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_runtest_setup(item):
|
||||
assert item.funcargs is None
|
||||
assert not hasattr(item, "_request")
|
||||
""")
|
||||
testdir.makepyfile("""
|
||||
def pytest_funcarg__a(request):
|
||||
|
||||
Reference in New Issue
Block a user