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

Class TestCollectFS

testing/test_collection.py:139–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137
138
139class TestCollectFS:
140 def test_ignored_certain_directories(self, pytester: Pytester) -> None:
141 tmp_path = pytester.path
142 ensure_file(tmp_path / "build" / "test_notfound.py")
143 ensure_file(tmp_path / "dist" / "test_notfound.py")
144 ensure_file(tmp_path / "_darcs" / "test_notfound.py")
145 ensure_file(tmp_path / "CVS" / "test_notfound.py")
146 ensure_file(tmp_path / "{arch}" / "test_notfound.py")
147 ensure_file(tmp_path / ".whatever" / "test_notfound.py")
148 ensure_file(tmp_path / ".bzr" / "test_notfound.py")
149 ensure_file(tmp_path / "normal" / "test_found.py")
150 for x in tmp_path.rglob("test_*.py"):
151 x.write_text("def test_hello(): pass", encoding="utf-8")
152
153 result = pytester.runpytest("--collect-only")
154 s = result.stdout.str()
155 assert "test_notfound" not in s
156 assert "test_found" in s
157
158 known_environment_types = pytest.mark.parametrize(
159 "env_path",
160 [
161 pytest.param(PurePath("pyvenv.cfg"), id="venv"),
162 pytest.param(PurePath("conda-meta", "history"), id="conda"),
163 ],
164 )
165
166 @known_environment_types
167 def test_ignored_virtualenvs(self, pytester: Pytester, env_path: PurePath) -> None:
168 ensure_file(pytester.path / "virtual" / env_path)
169 testfile = ensure_file(pytester.path / "virtual" / "test_invenv.py")
170 testfile.write_text("def test_hello(): pass", encoding="utf-8")
171
172 # by default, ignore tests inside a virtualenv
173 result = pytester.runpytest()
174 result.stdout.no_fnmatch_line("*test_invenv*")
175 # allow test collection if user insists
176 result = pytester.runpytest("--collect-in-virtualenv")
177 assert "test_invenv" in result.stdout.str()
178 # allow test collection if user directly passes in the directory
179 result = pytester.runpytest("virtual")
180 assert "test_invenv" in result.stdout.str()
181
182 @known_environment_types
183 def test_ignored_virtualenvs_norecursedirs_precedence(
184 self, pytester: Pytester, env_path
185 ) -> None:
186 # norecursedirs takes priority
187 ensure_file(pytester.path / ".virtual" / env_path)
188 testfile = ensure_file(pytester.path / ".virtual" / "test_invenv.py")
189 testfile.write_text("def test_hello(): pass", encoding="utf-8")
190 result = pytester.runpytest("--collect-in-virtualenv")
191 result.stdout.no_fnmatch_line("*test_invenv*")
192 # ...unless the virtualenv is explicitly given on the CLI
193 result = pytester.runpytest("--collect-in-virtualenv", ".virtual")
194 assert "test_invenv" in result.stdout.str()
195
196 @known_environment_types

Callers

nothing calls this directly

Calls 2

parametrizeMethod · 0.80
paramMethod · 0.80

Tested by

no test coverage detected