-
-
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
TestIds not relative to rootdir & cannot be run as pytest args #11235
Comments
Hi @eleanorjboyd, The "node IDs" provided on the command line are in fact not relative to the rootdir, but to the "invocation dir", i.e. the working directory when pytest was invoked. This I think makes more sense than making them relative to the rootdir, because the user works in the context of the CWD, does auto-completion based on the CWD, etc. I don't think this is something we'll be changing. The docs are currently somewhat misleading in this regard, this was also mentioned in issue #11107. I'll be sending a PR soon to rectify this. |
Hi! Thanks for getting back to me and answering my question! This is very useful as I continue to work. One clarifying question, so what you're saying is that the "-c" parameter does not change the "invocation directory" since "-c" changes the root right? One issue I think I am still running into is when I add test_directory to my python path then run
To give another example of what I am saying, running pytest from the same directory should always result in the same testids (since the invocation directory does not change). But when I run
sorry this got lengthy but hopefully this explanation makes sense. Thanks! |
Hello again! I think I have figured it out, below is my solution. Since the nodeid is relative I calculate the difference between the root and the invocation path so my test_ids always have the relativity to the invocation location. calculate if there is a difference between root and invocation paths
update testids to always be relative to the invocation path
I think the biggest thing that confused me was running
from pytest/src/_pytest/config/__init__.py Line 1117 in 32f4808
Thank you for your help and for maintaining pytest! I appreciate it! |
One important thing to note is that what is printed by
Just to be precise, nodeids are relative to the rootdir. (Well most of the time... see #11245).
Makes sense, if you want the path relative the invocation location from the nodeid, you can do this.
What is
Right :) BTW, I am not sure exactly what you are doing with the nodeids, but you might want to avoid parsing the path of the nodeid entirely, and instead get the path from the Node itself, i.e. use |
appreciate your response here! Glad it all got straightened out and thanks for the extra clarification. I ended up moving forward with the node path for an absolute reference path and that seems to be working well. Thanks |
pip list
from the virtual environment you are usingMac ARM
pytest version: pytest 7.2.2
Hi! This question is a little different but tried to provide as much detail as possible to have the report be clear. Let me know if I can provide more information! I have a project structured as following:
root
└─ module
└─ tests
─└─ unittest
──└─ test_uppercase.py
──└─ pytest.init
I created the following demo which I have attached but this is the jist.
run the above script file.
have the given code for my plugin_ex
get the following output
You can see that with the init file in the first run the rootdir is listed as
rootdir: /Users/eleanorboyd/testingFiles/from_users/test_directory/tests
and the test ids as printed out through the plugin aretest ids from plugin: unittests/test_param.py::test_odd_even[4]
. But then when I try and run a given test via its testID it doesn't work and returns the error you see in the second run even though its root dir is still listed asrootdir: /Users/eleanorboyd/testingFiles/from_users/test_directory/tests
From what I got of the doc is that all testIDs would be relative to the rootDir and therefore the testID when the rootdir stays the same should also be the same.
The reason I am experiencing this bug is I want to get testIDs from a plugin and then be able to call the given test from the command line. Is this actually a bug or am I getting the testID incorrectly somewhere or misunderstanding the docs in that the testID is relative to the rootdir?
Appreciate any help!
TO REPRO:
run script.py from the following example code I uploaded
test_directory.zip
Output of pip list:
Package Version
exceptiongroup 1.1.2
iniconfig 2.0.0
packaging 23.1
pip 23.2
pluggy 1.2.0
pytest 7.4.0
setuptools 65.4.1
tomli 2.0.1
Thanks! Sorry for the length here
The text was updated successfully, but these errors were encountered: