-
-
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
Is pytest output guaranteed to contain test file paths to relative to cwd #7463
Comments
Hi @karrtikr, Those paths are actually related to the The best way to make sure you have the same |
Ah I see, but it'll always be relative to the I will get back here as soon as I can once the user replies, mind keeping this open for a while? |
I think it is possible, if the rootdir and the test file reside in different drives. So you are one of the vscode developres? Cool! You guys are doing great work. Btw, why are you interested in parsing the terminal output? I ask because for integration usually the best approach are hooks instead. |
Thanks, Python extension VSCode dev here 👋
That's fair. But for our extension, we force the rootdir to be the workspace root, and only support running test files inside the workspace root, so they should be on the same drive.
I am not entirely sure, we were parsing output long before I joined the team. Maybe because hooks were not there earlier, or were not sufficient? I can consult with my team on whether we want to move towards this. |
@nicoddemus Can you please point to these hooks which we can use to run pytest where we won't need to parse the result? |
Cool 👋
Oh I see. I remember @brettcannon tweeting something along the lines of parsing the output as an early implementation, but that is brittle because we don't treat our output as stable, but he was aware that hooks were the way to go.
They were introduced quite a long time ago, in 2010. I believe they should be more than enough to get any information you need from a pytest run, and they are quite stable. A quick example on how vscode could integrate with pytest using hooks: class MyPlugin:
def pytest_runtest_logreport(report):
if report.when == "call" and report.outcome == "passed":
print(f"{report.nodeid} passed")
pytest.main(["path to file.py::test name"], plugins=[MyPlugin()]) The list of hooks can be found in the API Reference, but I bet the more interesting ones for VS integration would be the reporting hooks. Please feel free to ask any questions, we are more than glad to help with getting the best pytest integration possible in vscode! |
So we use the hooks for discovery, but we don't for execution (yet; we plan to, but no clue on an ETA). |
Hey all 👋 It looks like we've answered this question so I'm closing the issue; feel free to open another if you have more questions. |
For instance, in my case I had run the following command and got this output
Tests\steve\hello_test.py
is not the absolute path here, but the path relative to my current working directory. Is it guaranteed to contain relative paths always?The text was updated successfully, but these errors were encountered: