Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest ignores test file if a single test method is called from the same test file #13240

Open
wohauser opened this issue Feb 20, 2025 · 5 comments

Comments

@wohauser
Copy link

We want to execute all tests from a test file and need to execute one test from this file afterwards.
In version 7.3.1 this worked well.
Since 8.3.4 we imagine following:

Reproduction:
content of test_test.py

class  TestClass(object):
	def test_test_1(self):
		print("Test1")
	def test_test_2(self):
		print("Test2")
	def test_test_3(self):
		print("Test3")

pytest -s test_test.py test_test.py::TestClass::test_test_3

Result:
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-8.3.4, pluggy-1.5.0
rootdir: /tmp
plugins: dependency-0.6.0, csv-3.0.0
collected 1 item

test_test.py Test3
.

============================== 1 passed in 0.02s ===============================

What we expect is like in version 7.3.1:
pytest -s test_test.py test_test.py::TestClass::test_test_3
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.3.1, pluggy-1.0.0
rootdir: /mnt/hgfs/shared
plugins: dependency-0.5.1, csv-3.0.0
collected 4 items

test_test.py Test1
.Test2
.Test3
.Test3
.

============================== 4 passed in 0.05s ===============================

@RonnyPfannschmidt
Copy link
Member

@bluetech could this be related to the directory handling

@wohauser
Copy link
Author

wohauser commented Feb 20, 2025

An other strange behavior:

test_test_1py

class  TestClass(object):
	def test_test_4(self):
		print("Test4")

pytest -s -rsxX test_test.py::TestClass::test_test_1 test_test.py::TestClass::test_test_2 test_test.py::TestClass::test_test_3 test_test.py::TestClass::test_test_2 test_test_1.py
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-8.3.4, pluggy-1.5.0
rootdir: /mnt/hgfs/shared
plugins: dependency-0.6.0, csv-3.0.0
collected 5 items

test_test.py Test1
.Test2
.Test3
.
test_test_1.py Test4
.

============================== 4 passed in 0.13s ===============================

We missing the 2nd Test2.
Here the same behavior as in 7.3.1

@wohauser
Copy link
Author

We expect that the methods and files given as commandline arguments are executed as provided in comandline.

@The-Compiler
Copy link
Member

could this be related to the directory handling

It is indeed, I was able to bisect the problem mentioned in the OP to:

commit 385796ba494e7ae65d55892d4a358b371ac7a6b6
Author: Ran Benita <[email protected]>
Date:   Fri Jun 2 16:03:39 2023 +0300

    Rework Session and Package collection

@bluetech
Copy link
Member

Yes, this is a duplicate of the cursed issue #12083.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants