-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetopic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config file
Description
I can reproduce this with a project set up as follows:
-
pyproject.toml:[tool.pytest.ini_options] python_files = "*.py" testpaths = [ "tests", ]
-
src/playground/__init__.pyexists and is empty -
src/playground/__main__.py:import sys def main(): print("Hello, world!") sys.exit(main())
-
testsdoes not exist
When I run pytest, I get this output:
============================= test session starts ==============================
platform linux -- Python 3.11.3, pytest-7.2.1, pluggy-1.0.0
rootdir: /home/charles/science/python/playground, configfile: pyproject.toml
plugins: cov-4.0.0
collected 0 items / 1 error
==================================== ERRORS ====================================
_________________ ERROR collecting src/playground/__main__.py __________________
src/playground/__main__.py:11: in <module>
sys.exit(main())
E SystemExit
------------------------------- Captured stdout --------------------------------
Hello, world!
=========================== short test summary info ============================
ERROR src/playground/__main__.py - SystemExit
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.03s ===============================
I would expect this to succesfully collect nothing and run no tests, but instead it fails because it runs __main__.py. Notably, if I remove python_files = "*.py" from pyproject.toml, it works. It seems like this shouldn't matter, though, because I'm already narrowing testpaths to tests.
Metadata
Metadata
Assignees
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetopic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config file