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

xdist master cant see workers' workeroutput when using --forked #87

Open
PatrikMosko opened this issue Nov 14, 2023 · 0 comments
Open

Comments

@PatrikMosko
Copy link

PatrikMosko commented Nov 14, 2023

Hi fellas.

I am building a tests profiler for collecting various statistics before/during test cases execution.
Since we use pytest-xdist, I decided its finally time to look into how new xdist hooks from newhooks.py work and try to get as much value out of them as possible, since doing shenanigans with locks and writing output to tmp files is pretty ugly.

I have finished my profiler MVP, and it was working nicely, until I tried to run it in our jenkins which uses --forked option.
setup
python-3.8.10
pytest-7.4.3
pytest-xdist-3.3.1
pytest-forked-1.6.0

ISSUE
Turned out no stats are being displayed when I use this option.
Inside pytest_testnodedown hook, where master node is collecting and aggregating collected statistics from all worker nodes, the node.workeroutput attribute is simply empty.

Is there some workaround for this, on how to properly send data from workers to master when using --forked? Am I just missing something?

Here are 2 most important hooks used for collecting and aggregating all the statistics.

    @pytest.hookimpl(hookwrapper=True, tryfirst=True)
    def pytest_sessionfinish(self):
        worker_id = get_xdist_worker_id(self)
        if worker_id != "master":
            # NOTE: Execnet can't serialize custom classes. Serialization has to be
            # implemented for everything we want to send in-between master and workers
            self.config.workeroutput[
                f"{worker_id}-stats"
            ] = self._profiling_stats.serialize()
        yield

    @pytest.hookimpl(trylast=True)
    def pytest_testnodedown(self, node):
        worker_id = node.workerinput["workerid"]
        node_stats = node.workeroutput[f"{worker_id}-stats"]
        node_stats = ProfilerNamespaceUnit.deserialize(node_stats)
        self._profiling_stats.merge_trees(node_stats)
@PatrikMosko PatrikMosko changed the title xdist master cant see workers workeroutput when using --forked xdist master cant see workers' workeroutput when using --forked Nov 14, 2023
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

No branches or pull requests

1 participant