def test_modulecol_roundtrip(pytester: Pytester) -> None: modcol = pytester.getmodulecol("pass", withinit=False) trail = modcol.nodeid newcol = modcol.session.perform_collect([trail], genitems=0)[0] assert modcol.name == newcol.name
def check_readme(self, pytester: Pytester) -> bool: config = pytester.parseconfigure() assert config.cache is not None readme = config.cache._cachedir.joinpath("README.md") return readme.is_file()
def test_syntax_error_in_module(self, pytester: Pytester) -> None: modcol = pytester.getmodulecol("this is a syntax error") pytest.raises(modcol.CollectError, modcol.collect) pytest.raises(modcol.CollectError, modcol.collect)
def test_module_considers_pluginmanager_at_import( self, pytester: Pytester) -> None: modcol = pytester.getmodulecol("pytest_plugins='xasdlkj',") pytest.raises(ImportError, lambda: modcol.obj)
def test_failing_import(self, pytester: Pytester) -> None: modcol = pytester.getmodulecol("import alksdjalskdjalkjals") pytest.raises(Collector.CollectError, modcol.collect)
def test_getmodulecollector(self, pytester: Pytester) -> None: item = pytester.getitem("def test_func(): pass") modcol = item.getparent(pytest.Module) assert isinstance(modcol, pytest.Module) assert hasattr(modcol.obj, "test_func")
def test_package_collection_infinite_recursion(pytester: Pytester) -> None: pytester.copy_example("collect/package_infinite_recursion") result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 passed*"])
def test_unicode_args(pytester: Pytester) -> None: result = pytester.runpytest("-k", "אבג") assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_func_reportinfo(self, pytester: Pytester) -> None: item = pytester.getitem("def test_func(): pass") fspath, lineno, modpath = item.reportinfo() assert str(fspath) == str(item.path) assert lineno == 0 assert modpath == "test_func"
def test_syntax_error_with_non_ascii_chars(pytester: Pytester) -> None: """Fix decoding issue while formatting SyntaxErrors during collection (#578).""" pytester.makepyfile("☃") result = pytester.runpytest() result.stdout.fnmatch_lines( ["*ERROR collecting*", "*SyntaxError*", "*1 error in*"])
def test_makefile_joins_absolute_path(pytester: Pytester) -> None: absfile = pytester.path / "absfile" p1 = pytester.makepyfile(**{str(absfile): ""}) assert str(p1) == str(pytester.path / "absfile.py")
def test_parseconfig(pytester: Pytester) -> None: config1 = pytester.parseconfig() config2 = pytester.parseconfig() assert config2 is not config1
def test_pytester_run_no_timeout(pytester: Pytester) -> None: testfile = pytester.makepyfile("def test_no_timeout(): pass") assert pytester.runpytest_subprocess(testfile).ret == ExitCode.OK
def test_readme_failed(self, pytester: Pytester) -> None: pytester.makepyfile("def test_always_fails(): assert 0") pytester.runpytest() assert self.check_readme(pytester) is True
def test_package_collection_init_given_as_argument(pytester: Pytester) -> None: """Regression test for #3749""" p = pytester.copy_example("collect/package_init_given_as_arg") result = pytester.runpytest(p / "pkg" / "__init__.py") result.stdout.fnmatch_lines(["*1 passed*"])
def test_lastfailed_creates_cache_when_needed(self, pytester: Pytester) -> None: # Issue #1342 pytester.makepyfile(test_empty="") pytester.runpytest("-q", "--lf") assert not os.path.exists(".pytest_cache/v/cache/lastfailed") pytester.makepyfile( test_successful="def test_success():\n assert True") pytester.runpytest("-q", "--lf") assert not os.path.exists(".pytest_cache/v/cache/lastfailed") pytester.makepyfile(test_errored="def test_error():\n assert False") pytester.runpytest("-q", "--lf") assert os.path.exists(".pytest_cache/v/cache/lastfailed")
def test_pytester_subprocess(pytester: Pytester) -> None: testfile = pytester.makepyfile("def test_one(): pass") assert pytester.runpytest_subprocess(testfile).ret == 0