def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage testdir.makeconftest(""" import pytest def pytest_pycollect_makeitem(collector, name, obj): if name == "MyClass": return MyCollector(name, parent=collector) class MyCollector(pytest.Collector): def reportinfo(self): return self.fspath, 3, "xyz" """) modcol = testdir.getmodulecol(""" import pytest @pytest.fixture def arg1(request): return 42 class MyClass(object): pass """) # this hook finds funcarg factories rep = runner.collect_one_node(collector=modcol) clscol = rep.result[0] clscol.obj = lambda arg1: None clscol.funcargs = {} pytest._fillfuncargs(clscol) assert clscol.funcargs['arg1'] == 42
def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage testdir.makeconftest( """ import pytest def pytest_pycollect_makeitem(collector, name, obj): if name == "MyClass": return MyCollector(name, parent=collector) class MyCollector(pytest.Collector): def reportinfo(self): return self.fspath, 3, "xyz" """ ) modcol = testdir.getmodulecol( """ import pytest @pytest.fixture def arg1(request): return 42 class MyClass(object): pass """ ) # this hook finds funcarg factories rep = runner.collect_one_node(collector=modcol) clscol = rep.result[0] clscol.obj = lambda arg1: None clscol.funcargs = {} pytest._fillfuncargs(clscol) assert clscol.funcargs["arg1"] == 42
def test_autouse_fixture(self, pytester: Pytester, recwarn) -> None: # rough jstests usage pytester.makeconftest(""" import pytest def pytest_pycollect_makeitem(collector, name, obj): if name == "MyClass": return MyCollector.from_parent(collector, name=name) class MyCollector(pytest.Collector): def reportinfo(self): return self.fspath, 3, "xyz" """) modcol = pytester.getmodulecol(""" import pytest @pytest.fixture(autouse=True) def hello(): pass @pytest.fixture def arg1(request): return 42 class MyClass(object): pass """) # this hook finds funcarg factories rep = runner.collect_one_node(modcol) # TODO: Don't treat as Any. clscol: Any = rep.result[0] clscol.obj = lambda: None clscol.funcargs = {} pytest._fillfuncargs(clscol) assert not clscol.funcargs
def test_autouse_fixture(self, testdir): # rough jstests usage testdir.makeconftest(""" import pytest def pytest_pycollect_makeitem(collector, name, obj): if name == "MyClass": return MyCollector(name, parent=collector) class MyCollector(pytest.Collector): def reportinfo(self): return self.fspath, 3, "xyz" """) modcol = testdir.getmodulecol(""" import pytest @pytest.fixture(autouse=True) def hello(): pass def pytest_funcarg__arg1(request): return 42 class MyClass: pass """) # this hook finds funcarg factories rep = modcol.ihook.pytest_make_collect_report(collector=modcol) clscol = rep.result[0] clscol.obj = lambda: None clscol.funcargs = {} pytest._fillfuncargs(clscol) assert not clscol.funcargs
def test_fillfuncargs_is_deprecated() -> None: with pytest.warns( pytest.PytestDeprecationWarning, match=re.escape( "pytest._fillfuncargs() is deprecated, use " "function._request._fillfixtures() instead if you cannot avoid reaching into internals." ), ): pytest._fillfuncargs(mock.Mock())
def test__fillfuncargs_is_deprecated() -> None: with pytest.warns( pytest.PytestDeprecationWarning, match="The `_fillfuncargs` function is deprecated", ): pytest._fillfuncargs(mock.Mock())