MCPcopy
hub / github.com/pytest-dev/pytest / test_pyargs_collection_tree

Function test_pyargs_collection_tree

testing/test_collection.py:1820–1862  ·  view source on GitHub ↗

When using `--pyargs`, the collection tree of a pyargs collection argument should only include parents in the import path, not up to confcutdir. Regression test for #11904.

(pytester: Pytester, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

1818
1819
1820def test_pyargs_collection_tree(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
1821 """When using `--pyargs`, the collection tree of a pyargs collection
1822 argument should only include parents in the import path, not up to confcutdir.
1823
1824 Regression test for #11904.
1825 """
1826 site_packages = pytester.path / "venv/lib/site-packages"
1827 site_packages.mkdir(parents=True)
1828 monkeypatch.syspath_prepend(site_packages)
1829 pytester.makepyfile(
1830 **{
1831 "venv/lib/site-packages/pkg/__init__.py": "",
1832 "venv/lib/site-packages/pkg/sub/__init__.py": "",
1833 "venv/lib/site-packages/pkg/sub/test_it.py": "def test(): pass",
1834 }
1835 )
1836
1837 result = pytester.runpytest("--pyargs", "--collect-only", "pkg.sub.test_it")
1838 assert result.ret == ExitCode.OK
1839 result.stdout.fnmatch_lines(
1840 [
1841 "<Package venv/lib/site-packages/pkg>",
1842 " <Package sub>",
1843 " <Module test_it.py>",
1844 " <Function test>",
1845 ],
1846 consecutive=True,
1847 )
1848
1849 # Now with an unrelated rootdir with unrelated files.
1850 monkeypatch.chdir(tempfile.gettempdir())
1851
1852 result = pytester.runpytest("--pyargs", "--collect-only", "pkg.sub.test_it")
1853 assert result.ret == ExitCode.OK
1854 result.stdout.fnmatch_lines(
1855 [
1856 "<Package *pkg>",
1857 " <Package sub>",
1858 " <Module test_it.py>",
1859 " <Function test>",
1860 ],
1861 consecutive=True,
1862 )
1863
1864
1865def test_do_not_collect_symlink_siblings(

Callers

nothing calls this directly

Calls 6

syspath_prependMethod · 0.80
fnmatch_linesMethod · 0.80
mkdirMethod · 0.45
makepyfileMethod · 0.45
runpytestMethod · 0.45
chdirMethod · 0.45

Tested by

no test coverage detected