pytest icon indicating copy to clipboard operation
pytest copied to clipboard

When both a directory and a file are passed on the CLI, only the file is run

Open JelleZijlstra opened this issue 5 months ago • 0 comments

When the command-line args include both a directory with test files and a specific test file in that directory, pytest runs only the file and not the other files in that directory.

As an example:

$ pytest --collect-only pycroscope/ pycroscope/test_analysis_lib.py 
================================================================================================= test session starts =================================================================================================
platform darwin -- Python 3.12.2, pytest-8.4.0, pluggy-1.5.0
rootdir: /Users/jelle/py/pycroscope
configfile: pyproject.toml
collected 3 items                                                                                                                                                                                                     

<Dir pycroscope>
  <Package pycroscope>
    <Module test_analysis_lib.py>
      <Function test_get_indentation>
      <Function test_get_line_range_for_node>
      <Function test_object_from_string>

============================================================================================= 3 tests collected in 0.10s ==============================================================================================
$ pytest --collect-only pycroscope/
================================================================================================= test session starts =================================================================================================
platform darwin -- Python 3.12.2, pytest-8.4.0, pluggy-1.5.0
rootdir: /Users/jelle/py/pycroscope
configfile: pyproject.toml
collected 1026 items / 3 skipped                                                                                                                                                                                      

This is dangerous because it can lead us to silently skip running some tests.

JelleZijlstra avatar Jun 06 '25 19:06 JelleZijlstra