pytest-dev / pytest-dev/pytest-xdist

pytest-xdist throws AssertionError when remote script has pytest_collection_modifyitems() hook

Open
#674 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

I have a remote script that needs to be executed by xdist, which I am giving through the hook pytest_xdist_getremotemodule(), I am performing some collection changes, that are common to all nodes through pytest_collection_modifyitems(), but during the runtestloop the worker fails with AssertionError

platform darwin -- Python 3.9.1, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /usr/local/opt/python@3.9/bin/python3.9
cachedir: .pytest_cache
rootdir: /Users/akhileshr/Projects/pytest_test, configfile: pytest.ini
plugins: xdist-2.2.1, easyread-0.1.0, forked-1.3.0
[gw0] darwin Python 3.9.1 cwd: /Users/akhileshr/Projects/pytest_test
[gw1] darwin Python 3.9.1 cwd: /Users/akhileshr/Projects/pytest_test
[gw0] Python 3.9.1 (default, Jan  8 2021, 17:17:43)  -- [Clang 12.0.0 (clang-1200.0.32.28)]
[gw1] Python 3.9.1 (default, Jan  8 2021, 17:17:43)  -- [Clang 12.0.0 (clang-1200.0.32.28)]
gw0 [6] / gw1 [6]
scheduling tests via LoadScheduling
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/xdist/dsession.py", line 112, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/xdist/dsession.py", line 135, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/Users/akhileshr/Projects/pytest_test/pytest_bypass.py", line 62, in worker_workerfinished
INTERNALERROR>     assert not crashitem, (crashitem, node)
INTERNALERROR> AssertionError: ('dum_py.py::test_pytestDum', <WorkerController gw1>)

The testscript has a simple assertion statement 1==1

When I remove the pytest_collection_modifyitems() function from remote script, the program works without any issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the remote-script setup using pytest_xdist_getremotemodule() together with pytest_collection_modifyitems(), then inspect pytest_bypass.py at line 62 and the xdist/dsession.py traceback path. Done means the described collection-hook scenario completes without the worker_finished AssertionError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.