pytest-dev / pytest-dev/pytest-forked
xdist master cant see workers' workeroutput when using --forked
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 83
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the pytest_sessionfinish and pytest_testnodedown hooks described in the issue, alongside pytest-forked's handling of --forked and the referenced newhooks.py. Reproduce with the listed Python, pytest, pytest-xdist, and pytest-forked versions. Done means worker statistics are available to the master during pytest_testnodedown when --forked is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100