-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Incorrect number of collected items reported when specific class methods are provided #2464
Comments
Just to be clear here: the problem is that it should display |
@nicoddemus Is it documented somewhere? I expected |
That's perfectly reasonable to assume, it it is just not how things work currently. To discover test items from a module, pytest has to import that module. At that point it creates the test items it finds in that namespace, and only then it picks out the test id provided in the command line to execute. It does so because it has to create a test item in order to know its node id (to account for parametrization, hooks, etc, anything which in the end affects the node id), so it might as well create all test items for a module upon discovery. |
@nicoddemus Thank you for the explanation, it makes more sense now. |
It seems that the number of collected tests is displayed incorrectly when the "class method" notation (
ModuleX::ClassY::MethodZ
) is used from the command line. In a simple example (see below) when we want to collect/run only one specific test method from a class, one expects to get the message that only 1 item was collected (collected 1 item
). Instead,pytest
outputscollected N items
, where N equals the total number of test methods collected fromClassY
plus one.pip list
of the virtual environment you are using$ py.test collect.py::TestClass::test_main --collect-only
Output:
Expected output:
The text was updated successfully, but these errors were encountered: