AssertionError: ('conftest.py::ruff::format', <WorkerController gw3>)
I run it into my docker container and I have just part of tests passed. Another part is skipped and I have an error without ruff output:
web-1 | [gw7] [ 31%] PASSED accounting/__init__.py::ruff::format web-1 |
web-1 | INTERNALERROR> def worker_internal_error(
web-1 | INTERNALERROR> self, node: WorkerController, formatted_error: str
web-1 | INTERNALERROR> ) -> None:
web-1 | INTERNALERROR> """
web-1 | INTERNALERROR> pytest_internalerror() was called on the worker.
web-1 | INTERNALERROR>
web-1 | INTERNALERROR> pytest_internalerror() arguments are an excinfo and an excrepr, which can't
web-1 | INTERNALERROR> be serialized, so we go with a poor man's solution of raising an exception
web-1 | INTERNALERROR> here ourselves using the formatted message.
web-1 | INTERNALERROR> """
web-1 | INTERNALERROR> self._active_nodes.remove(node)
web-1 | INTERNALERROR> try:
web-1 | INTERNALERROR> > assert False, formatted_error
web-1 | INTERNALERROR> E AssertionError: Traceback (most recent call last):
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 271, in wrap_session
web-1 | INTERNALERROR> E session.exitstatus = doit(config, session) or 0
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 325, in _main
web-1 | INTERNALERROR> E config.hook.pytest_runtestloop(session=session)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
web-1 | INTERNALERROR> E return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
web-1 | INTERNALERROR> E return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 182, in _multicall
web-1 | INTERNALERROR> E return outcome.get_result()
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 100, in get_result
web-1 | INTERNALERROR> E raise exc.with_traceback(exc.__traceback__)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
web-1 | INTERNALERROR> E res = hook_impl.function(*args)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/xdist/remote.py", line 174, in pytest_runtestloop
web-1 | INTERNALERROR> E self.run_one_test()
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/xdist/remote.py", line 195, in run_one_test
web-1 | INTERNALERROR> E self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
web-1 | INTERNALERROR> E return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
web-1 | INTERNALERROR> E return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 182, in _multicall
web-1 | INTERNALERROR> E return outcome.get_result()
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 100, in get_result
web-1 | INTERNALERROR> E raise exc.with_traceback(exc.__traceback__)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
web-1 | INTERNALERROR> E res = hook_impl.function(*args)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
web-1 | INTERNALERROR> E runtestprotocol(item, nextitem=nextitem)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/_pytest/runner.py", line 133, in runtestprotocol
web-1 | INTERNALERROR> E reports.append(call_and_report(item, "call", log))
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/_pytest/runner.py", line 224, in call_and_report
web-1 | INTERNALERROR> E report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
web-1 | INTERNALERROR> E return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
web-1 | INTERNALERROR> E return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 156, in _multicall
web-1 | INTERNALERROR> E teardown[0].send(outcome)
web-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pytest_docker_tools/plugin.py", line 31, in pytest_runtest_makereport
web-1 | INTERNALERROR> E if "request" not in item.funcargs:
web-1 | INTERNALERROR> E AttributeError: 'RuffFormatItem' object has no attribute 'funcargs'
web-1 | INTERNALERROR> E assert False
web-1 | INTERNALERROR>
web-1 | INTERNALERROR> /usr/local/lib/python3.10/site-packages/xdist/dsession.py:232: AssertionError
web-1 | INTERNALERROR> Traceback (most recent call last):
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 271, in wrap_session
web-1 | INTERNALERROR> session.exitstatus = doit(config, session) or 0
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 325, in _main
web-1 | INTERNALERROR> config.hook.pytest_runtestloop(session=session)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
web-1 | INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
web-1 | INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 182, in _multicall
web-1 | INTERNALERROR> return outcome.get_result()
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 100, in get_result
web-1 | INTERNALERROR> raise exc.with_traceback(exc.__traceback__)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
web-1 | INTERNALERROR> res = hook_impl.function(*args)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/xdist/dsession.py", line 138, in pytest_runtestloop
web-1 | INTERNALERROR> self.loop_once()
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/xdist/dsession.py", line 163, in loop_once
web-1 | INTERNALERROR> call(**kwargs)
web-1 | INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/xdist/dsession.py", line 217, in worker_workerfinished
web-1 | INTERNALERROR> assert not crashitem, (crashitem, node)
web-1 | INTERNALERROR> AssertionError: ('conftest.py::ruff::format', <WorkerController gw3>)
web-1 | INTERNALERROR> assert not 'conftest.py::ruff::format'
web-1 |
web-1 | =========== 89 passed, 54 skipped, 199 warnings in 69.76s (0:01:09) ============
web-1 | web-1 | web-1 | web-1 |
This is my pytest-related requirements
pytest==8.3.3
pytest-django==4.8.0
pytest-lazy-fixtures==1.1.1
pytest-celery==1.1.3
pytest-factoryboy==2.7.0
pytest-xdist==3.6.1
pytest-recording==0.13.2
pytest-profiling==1.7.0
pytest-cov==5.0.0
pytest-ruff==0.4.1
pytest.ini
[pytest]
addopts = --reuse-db --no-migrations --create-db
-n auto --dist loadgroup
--ruff --ruff-format
Probably it is related to https://github.com/businho/pytest-ruff/issues/28. I run on Windows too, but in docker-compose.
When I run without xdist just, it's not much better.
[pytest]
addopts = --reuse-db --no-migrations --create-db
--ruff --ruff-format
Welcome! Im getting the same error message.
The error occurs due to pytest-celery, which internally uses pytest-docker-tools. In pytest-docker-tools, the file plugin.py contains the following hook:
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
"""
This hook allows Docker containers to contribute their logs to the py.test
report.
"""
outcome = yield
rep = outcome.get_result()
if not rep.failed:
return
if call.excinfo and isinstance(call.excinfo.value, ContainerError):
container = call.excinfo.value._container
rep.sections.append((container.name, container.logs()))
if "request" not in item.funcargs:
return
for name, fixturedef in item.funcargs["request"]._fixture_defs.items():
if not hasattr(fixturedef, "cached_result") or not fixturedef.cached_result:
continue
fixture = fixturedef.cached_result[0]
if isinstance(fixture, Container):
rep.sections.append(
(
name + ": " + fixture.name,
fixture.logs(),
)
)
When running tests, the hook is triggered, and the following error occurs:
b-1 | INTERNALERROR> E File "/usr/local/lib/python3.10/site-packages/pytest_docker_tools/plugin.py", line 31, in pytest_runtest_makereport
web-1 | INTERNALERROR> E if "request" not in item.funcargs:
web-1 | INTERNALERROR> E AttributeError: 'RuffFormatItem' object has no attribute 'funcargs'
web-1 | INTERNALERROR> E assert False
In my project's conftest.py, I can add the following hook to make the error disappear, but this doesn't seem like an elegant solution:
@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(items):
for item in items:
if item.__class__.__name__ in ("RuffItem", "RuffFormatItem"):
item.funcargs = {}
What would you recommend to solve the problem? Should I fix the problem in my conftest.py file, or is there something that can be done on the pytest-ruff side?
@businho, is it problem of your repo or pytest-docker-tools? What do you think? Should I create issue in it?