allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
713 stars 233 forks source link

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

Open hokor opened 2 months ago

hokor commented 2 months ago

[//]: # ( . Note: for support questions, please use Stackoverflow or Gitter. . This repository's issues are reserved for feature requests and bug reports. . . In case of any problems with Allure Jenkins plugin please use the following repository . to create an issue: https://github.com/jenkinsci/allure-plugin/issues . . Make sure you have a clear name for your issue. The name should start with a capital . letter and no dot is required in the end of the sentence. An example of good issue names: . . - The report is broken in IE11 . - Add an ability to disable default plugins . - Support emoji in test descriptions )

I'm submitting a ...

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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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:

[//]: # ( . e.g. detailed explanation, stacktraces, related issues, suggestions . how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc )