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

Make the plugin compatible with pytest-xdist #51

Merged
merged 1 commit into from
Nov 16, 2022

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 15, 2022

The pytest-xdist plugin spawns worker processes that run the tests while
the main process reports the results. As every process has its own copy
of all the plugins, this means that when the main process reports the
final summary, it doesn't have access to the results stored by every
individual test so the plugin is unable to print the summary.

To make ourselves compatible with pytest-xdist, we make the main process
and the workers use a common path to store the metadata and result files
(this is communicated from the main process to the workers by an
environment variable). Then, at report time, if the main process doesn't
have any result data, it will fetch it from this directory instead.

Closes: #2

pyproject.toml Outdated Show resolved Hide resolved
src/pytest_memray/plugin.py Outdated Show resolved Hide resolved
src/pytest_memray/plugin.py Outdated Show resolved Hide resolved
src/pytest_memray/plugin.py Outdated Show resolved Hide resolved
@godlygeek
Copy link
Contributor

pytest-xdist allows distributing tests across multiple hosts, as well. Should we detect when it was run in that mode and warn or fail?

@pablogsal
Copy link
Member Author

pytest-xdist allows distributing tests across multiple hosts, as well. Should we detect when it was run in that mode and warn or fail?

Hummm. I would need to investigate. Do you mind if we do this in a another PR?

The pytest-xdist plugin spawns worker processes that run the tests while
the main process reports the results. As every process has its own copy
of all the plugins, this means that when the main process reports the
final summary, it doesn't have access to the results stored by every
individual test so the plugin is unable to print the summary.

To make ourselves compatible with pytest-xdist, we make the main process
and the workers use a common path to store the metadata and result files
(this is communicated from the main process to the workers by an
environment variable). Then, at report time, if the main process doesn't
have any result data, it will fetch it from this directory instead.

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@pablogsal
Copy link
Member Author

I have addressed all comments, please take another look

@pablogsal pablogsal merged commit 35d8d60 into bloomberg:main Nov 16, 2022
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

Successfully merging this pull request may close these issues.

Empty report when running with pytest-xdist
3 participants