|
3 | 3 | from _pytest.pytester import Pytester |
4 | 4 |
|
5 | 5 |
|
6 | | -def test_no_items_should_not_show_output(pytester: Pytester) -> None: |
| 6 | +def test_should_show_no_output_when_zero_items(pytester: Pytester) -> None: |
7 | 7 | result = pytester.runpytest("--fixtures-per-test") |
8 | 8 | result.stdout.no_fnmatch_line("*fixtures used by*") |
9 | 9 | assert result.ret == 0 |
@@ -254,3 +254,75 @@ def test_arg1(arg1): |
254 | 254 | " Docstring content that extends into a third paragraph.", |
255 | 255 | ] |
256 | 256 | ) |
| 257 | + |
| 258 | + |
| 259 | +def test_should_not_show_direct_param_fixtures(pytester: Pytester) -> None: |
| 260 | + """A direct-param fixture is a helper fixture created as an implementation |
| 261 | + detail of direct parametrization. |
| 262 | +
|
| 263 | + These fixtures should not be included in the output because they don't |
| 264 | + satisfy user expectations for how fixtures are created and used (#11295). |
| 265 | + """ |
| 266 | + pytester.makepyfile( |
| 267 | + """ |
| 268 | + import pytest |
| 269 | +
|
| 270 | + @pytest.mark.parametrize("x", [1]) |
| 271 | + def test_pseudo_fixture(x): |
| 272 | + pass |
| 273 | + """ |
| 274 | + ) |
| 275 | + result = pytester.runpytest("--fixtures-per-test") |
| 276 | + result.stdout.no_fnmatch_line("*fixtures used by*") |
| 277 | + assert result.ret == 0 |
| 278 | + |
| 279 | + |
| 280 | +def test_should_show_parametrized_fixtures_used_by_test(pytester: Pytester) -> None: |
| 281 | + """A fixture with parameters should be included if it was created using |
| 282 | + the @pytest.fixture decorator, including those that are indirectly |
| 283 | + parametrized.""" |
| 284 | + pytester.makepyfile( |
| 285 | + ''' |
| 286 | + import pytest |
| 287 | +
|
| 288 | + @pytest.fixture(params=['a', 'b']) |
| 289 | + def directly(request): |
| 290 | + """parametrized fixture""" |
| 291 | + return request.param |
| 292 | +
|
| 293 | + @pytest.fixture |
| 294 | + def indirectly(request): |
| 295 | + """indirectly parametrized fixture""" |
| 296 | + return request.param |
| 297 | +
|
| 298 | + def test_directly_parametrized_fixture(directly): |
| 299 | + pass |
| 300 | +
|
| 301 | + @pytest.mark.parametrize("indirectly", ["a", "b"], indirect=True) |
| 302 | + def test_indirectly_parametrized_fixture(indirectly): |
| 303 | + pass |
| 304 | + ''' |
| 305 | + ) |
| 306 | + result = pytester.runpytest("--fixtures-per-test") |
| 307 | + assert result.ret == 0 |
| 308 | + |
| 309 | + result.stdout.fnmatch_lines( |
| 310 | + [ |
| 311 | + "*fixtures used by test_directly_parametrized_fixture*", |
| 312 | + "*(test_should_show_parametrized_fixtures_used_by_test.py:14)*", |
| 313 | + "directly -- test_should_show_parametrized_fixtures_used_by_test.py:4", |
| 314 | + " parametrized fixture", |
| 315 | + "*fixtures used by test_directly_parametrized_fixture*", |
| 316 | + "*(test_should_show_parametrized_fixtures_used_by_test.py:14)*", |
| 317 | + "directly -- test_should_show_parametrized_fixtures_used_by_test.py:4", |
| 318 | + " parametrized fixture", |
| 319 | + "*fixtures used by test_indirectly_parametrized_fixture*", |
| 320 | + "*(test_should_show_parametrized_fixtures_used_by_test.py:17)*", |
| 321 | + "indirectly -- test_should_show_parametrized_fixtures_used_by_test.py:9", |
| 322 | + " indirectly parametrized fixture", |
| 323 | + "*fixtures used by test_indirectly_parametrized_fixture*", |
| 324 | + "*(test_should_show_parametrized_fixtures_used_by_test.py:17)*", |
| 325 | + "indirectly -- test_should_show_parametrized_fixtures_used_by_test.py:9", |
| 326 | + " indirectly parametrized fixture", |
| 327 | + ] |
| 328 | + ) |
0 commit comments