Skip to content

Behavior change in test discovery for "" with pytest 9 #13925

@TomAugspurger

Description

@TomAugspurger

pytest 9 changed how the empty string "" is interpreted when invoking pytest with multiple test files / directories.

This is almost surely caused by fixing #12083.

Given a layout like

test_root.py
a/
  test_a.py

with contents

# file: test_root.py
1/0

and

# file: a/test_a.py
def test_foo():
    pass

here's the output with pytest<9

❯ pytest -q '' a/
.                                                                                                                                                                                                                                       [100%]
1 passed in 0.14s

and with pytest==9.0.0

❯ pytest -q '' a/                                                                                                                                                                                                                       (base) 

=================================================================================================================== ERRORS ====================================================================================================================
_____________________________________________________________________________________________________ ERROR collecting debug/test_root.py _____________________________________________________________________________________________________
test_root.py:1: in <module>
    1/0
E   ZeroDivisionError: division by zero
=========================================================================================================== short test summary info ===========================================================================================================
ERROR test_root.py - ZeroDivisionError: division by zero
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.29s

My main question is how '' specifically should be interpreted by pytest. Should it be the current directory? Or error?

But overall I think pytest's new behavior is much improved, and we were just being a bit sloppy with how we called pytest. Perhaps we were just relying on undefined behavior previously, in which case closing this as "won't fix" sounds good to me.

xref rapidsai/cudf#20570


Version info:

❯ uv pip list                                                                                                                                                                                                                           (base) 
Package   Version
--------- -------
iniconfig 2.3.0
packaging 25.0
pluggy    1.6.0
pygments  2.19.2
pytest    8.4.2

pytest: 8.4.2 / 9.0.0
OS: linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: selectionrelated to test selection from the command linetype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions