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)
| 1818 | |
| 1819 | |
| 1820 | def 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 | |
| 1865 | def test_do_not_collect_symlink_siblings( |
nothing calls this directly
no test coverage detected