Skip to content

Can no longer group test cases by non-str attribute #1215

Open
@sshane

Description

@sshane

We used to be able to group test cases in xdist by a hashable class attribute (added by parameterized_class), now it assumes that it's always a string. Broken by #1201

https://github.com/commaai/openpilot/blame/fcebb5eb9f8735b6516a70f630c28f297c252c6a/selfdrive/car/tests/test_models.py#L474

test_route is a dataclass

@parameterized_class(('platform', 'test_route'), get_test_cases())
@pytest.mark.xdist_group_class_property('test_route')
class TestCarModel(TestCarModelBase):
  pass
batman@workstation-shane:~/openpilot/selfdrive/car/tests$ pytest -n1 test_models.py 
================================================================================== test session starts ==================================================================================
platform linux -- Python 3.12.4, pytest-8.4.0, pluggy-1.6.0
Using --randomly-seed=3682492429
rootdir: /home/batman/openpilot
configfile: pyproject.toml
plugins: repeat-0.9.4, subtests-0.14.1, timeout-2.4.0, mock-3.14.0, asyncio-0.26.0, randomly-3.16.0, cov-6.1.1, cpp-2.6.0, hypothesis-6.47.5, xdist-3.7.0
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
1 worker [1932 items]  
INTERNALERROR> def worker_internal_error(
INTERNALERROR>         self, node: WorkerController, formatted_error: str
INTERNALERROR>     ) -> None:
INTERNALERROR>         """
INTERNALERROR>         pytest_internalerror() was called on the worker.
INTERNALERROR>     
INTERNALERROR>         pytest_internalerror() arguments are an excinfo and an excrepr, which can't
INTERNALERROR>         be serialized, so we go with a poor man's solution of raising an exception
INTERNALERROR>         here ourselves using the formatted message.
INTERNALERROR>         """
INTERNALERROR>         self._active_nodes.remove(node)
INTERNALERROR>         try:
INTERNALERROR> >           assert False, formatted_error
INTERNALERROR> E           AssertionError: Traceback (most recent call last):
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/main.py", line 289, in wrap_session
INTERNALERROR> E                 session.exitstatus = doit(config, session) or 0
INTERNALERROR> E                                      ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/main.py", line 342, in _main
INTERNALERROR> E                 config.hook.pytest_collection(session=session)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> E                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR> E                 raise exception
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR> E                 teardown.throw(exception)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/logging.py", line 788, in pytest_collection
INTERNALERROR> E                 return (yield)
INTERNALERROR> E                         ^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR> E                 teardown.throw(exception)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/warnings.py", line 99, in pytest_collection
INTERNALERROR> E                 return (yield)
INTERNALERROR> E                         ^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR> E                 teardown.throw(exception)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1450, in pytest_collection
INTERNALERROR> E                 return (yield)
INTERNALERROR> E                         ^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E                       ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/main.py", line 353, in pytest_collection
INTERNALERROR> E                 session.perform_collect()
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/main.py", line 816, in perform_collect
INTERNALERROR> E                 hook.pytest_collection_modifyitems(
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> E                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR> E                 raise exception
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR> E                 teardown.throw(exception)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 443, in pytest_collection_modifyitems
INTERNALERROR> E                 res = yield
INTERNALERROR> E                       ^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR> E                 teardown.throw(exception)
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 373, in pytest_collection_modifyitems
INTERNALERROR> E                 res = yield
INTERNALERROR> E                       ^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E                       ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E               File "/home/batman/openpilot/.venv/lib/python3.12/site-packages/xdist/remote.py", line 254, in pytest_collection_modifyitems
INTERNALERROR> E                 item._nodeid = f"{item.nodeid}@{'_'.join(sorted(gnames))}"
INTERNALERROR> E                                                 ^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> E             TypeError: sequence item 0: expected str instance, CarTestRoute found
INTERNALERROR> E           assert False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions