-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
Clarify if parallel test execution affects pytest_sessionstart #12341
Comments
Pants executes each test file seperately via pytest in a seperate process with no other coordination. Almost literally: So the pytest integration is "dumb" in this regard as nearly all Pants integrations with tools are by default. In general, Pants just creates a hermetic filesystem tree and executes the smallest performant cacheable unit of work it can in a subprocess. |
So, if Pants did gain support in the core rules or a library, there would be two seperate cases:
This definitely may be useful / improve test throughput in certain cases, but its also non-trivial afaict, |
Thanks for the explanation @jsirois At present I would only need something for scenario 1:
Is there any way to tell For example, before running |
There is not that I'm aware of. I do feel like someone was working on this feature though. You might ask on pantsbuild Slack though.
I think that would be one path to hack - yes. I will note I personally do simply use an (two actually) interprocess lock over in Pex which uses tox / pytest-xdist: https://github.com/pantsbuild/pex/blob/5a7c0939392d6b462ca60d77393e5175284a1e67/pex/testing.py#L434-L479. In that example the |
There is! There is a plugin hook with the pants/src/python/pants/backend/python/goals/pytest_runner.py Lines 102 to 128 in ad3dded
And a simple example: pants/src/python/pants/backend/python/goals/pytest_runner_integration_test.py Lines 429 to 499 in ad3dded
We're happy to help at #plugins channel in Slack (or here) with developing a plugin. |
That was it. Its a bit unfortunate though since ~everyone will need to write a plugin. It would be great if we had a more declarative way to do this with BUILD file target metadata, etc. |
Agreed. Fwit, this plugin is how we implement |
Thanks @Eric-Arellano Just to be sure I understand. If I have N In my case, the majority of tests are unit tests and don't need any kind of extra initialization. It's only a few integration tests that do, and they are not always executed (unlike the unit tests). P.S. I agree with John about using a declarative way being better, but this is a good start. |
Yes. You can set the
Agreed. The trick is finding something generic enough for multiple organizations to benefit from, and that all the logic can be expressed via BUILD files. That worked with |
Hey @foobar-coder , how is this going? Feel free to head to Slack in the #plugins channel for help: https://www.pantsbuild.org/docs/getting-help I'm going to close, but still feel free to respond and ask questions. |
I am wondering if
pytest_sessionstart
is executed only once whenpants
runs Python tests in parallelThere are libraries out there to control single execution of setup code for
xdist
(e.g., seepytest-xdist
's issue #271).But it's unclear to me if
pants
needs something like that.I could look into the source code but I am looking for some sort of "official" answer for this.
(I know that the
--debug
option forces non-parallel execution but that's too slow)The text was updated successfully, but these errors were encountered: