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

pytest-xdist run tests with --clean-alluredir may fail when faker installed. #807

Open
1 of 3 tasks
hokor opened this issue Apr 18, 2024 · 0 comments
Open
1 of 3 tasks

Comments

@hokor
Copy link
Contributor

hokor commented Apr 18, 2024

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

pytest-xdist run tests with --clean-alluredir may fail. Because the {alluredir} already deleted by another woeker.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

create a test file :
test.py

def test_01():
    assert True

install the pytest, allure-pytest and pytest-xdist

pip install pytest allure-pytest pytest-xdist faker

Run tests multiple times
pytest test.py -n 10 --clean-alluredir --alluredir=/tmp/allure-results

And your will get a error:

pytest test.py -n 10  --clean-alluredir --alluredir=/tmp/allure-results
============================================================================================== test session starts ===============================================================================================
platform darwin -- Python 3.10.13, pytest-8.1.1, pluggy-1.4.0
rootdir: /private/tmp/allure-test
plugins: allure-pytest-2.13.5, Faker-24.11.0, xdist-3.5.0
initialized: 7/10 workersINTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/main.py", line 281, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1121, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 523, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self._hookimpls.copy(), kwargs, False)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/allure_pytest/plugin.py", line 167, in pytest_configure
INTERNALERROR>     file_logger = AllureFileLogger(report_dir, clean)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/allure_commons/logger.py", line 18, in __init__
INTERNALERROR>     shutil.rmtree(self._report_dir)
INTERNALERROR>   File "/opt/homebrew/Cellar/[email protected]/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 721, in rmtree
INTERNALERROR>     onerror(os.open, path, sys.exc_info())
INTERNALERROR>   File "/opt/homebrew/Cellar/[email protected]/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 718, in rmtree
INTERNALERROR>     fd = os.open(path, os.O_RDONLY)
INTERNALERROR> FileNotFoundError: [Errno 2] No such file or directory: '/tmp/allure-results'
initialized: 10/10 workersINTERNALERROR> def worker_internal_error(self, node, formatted_error):
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 "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/main.py", line 281, in wrap_session
INTERNALERROR> E                 config._do_configure()
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1121, in _do_configure
INTERNALERROR> E                 self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 523, in call_historic
INTERNALERROR> E                 res = self._hookexec(self.name, self._hookimpls.copy(), kwargs, False)
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
INTERNALERROR> E                 raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/allure_pytest/plugin.py", line 167, in pytest_configure
INTERNALERROR> E                 file_logger = AllureFileLogger(report_dir, clean)
INTERNALERROR> E               File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/allure_commons/logger.py", line 18, in __init__
INTERNALERROR> E                 shutil.rmtree(self._report_dir)
INTERNALERROR> E               File "/opt/homebrew/Cellar/[email protected]/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 721, in rmtree
INTERNALERROR> E                 onerror(os.open, path, sys.exc_info())
INTERNALERROR> E               File "/opt/homebrew/Cellar/[email protected]/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 718, in rmtree
INTERNALERROR> E                 fd = os.open(path, os.O_RDONLY)
INTERNALERROR> E             FileNotFoundError: [Errno 2] No such file or directory: '/tmp/allure-results'
INTERNALERROR> E           assert False
INTERNALERROR>
INTERNALERROR> .venv/lib/python3.10/site-packages/xdist/dsession.py:200: AssertionError
[gw0] node down: Not properly terminated

replacing crashed worker gw0
initialized: 11/11 workersINTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/main.py", line 285, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/main.py", line 339, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/_pytest/logging.py", line 806, in pytest_runtestloop
INTERNALERROR>     return (yield)  # Run all the tests.
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/xdist/dsession.py", line 123, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/xdist/dsession.py", line 148, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/private/tmp/allure-test/.venv/lib/python3.10/site-packages/xdist/dsession.py", line 238, in worker_errordown
INTERNALERROR>     self._active_nodes.remove(node)
INTERNALERROR> KeyError: <WorkerController gw0>

============================================================================================= no tests ran in 0.81s ==============================================================================================

What is the expected behavior?

no error raise.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

Other information

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

Successfully merging a pull request may close this issue.

1 participant