Title: allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests · Issue #757 · allure-framework/allure-python · GitHub
Open Graph Title: allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests · Issue #757 · allure-framework/allure-python
X Title: allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests · Issue #757 · allure-framework/allure-python
Description: I'm submitting a ... bug report What is the current behavior? I have a function that creates a thread which writes some information in the log. When I try to call it from pytest_generate_tests allure-pytest raises the following StopItera...
Open Graph Description: I'm submitting a ... bug report What is the current behavior? I have a function that creates a thread which writes some information in the log. When I try to call it from pytest_generate_tests allu...
X Description: I'm submitting a ... bug report What is the current behavior? I have a function that creates a thread which writes some information in the log. When I try to call it from pytest_generate_tests ...
Opengraph URL: https://github.com/allure-framework/allure-python/issues/757
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests","articleBody":"#### I'm submitting a ... \r\n - [x] bug report\r\n\r\n#### What is the current behavior?\r\nI have a function that creates a thread which writes some information in the log. When I try to call it from `pytest_generate_tests` allure-pytest raises the following `StopIteration` exception:\r\n```\r\nplatform linux -- Python 3.9.16, pytest-7.4.0, pluggy-1.2.0\r\nrootdir: /mnt/c/storage/allure_bug\r\nplugins: allure-pytest-2.13.2\r\ncollecting ... Exception in thread Thread-1:\r\nTraceback (most recent call last):\r\n File \"/usr/lib/python3.9/threading.py\", line 980, in _bootstrap_inner\r\n self.run()\r\n File \"/usr/lib/python3.9/threading.py\", line 917, in run\r\n self._target(*self._args, **self._kwargs)\r\n File \"/mnt/c/storage/allure_bug/conftest.py\", line 17, in _thread\r\n log.warning('thread')\r\n File \"/usr/lib/python3.9/logging/init.py\", line 1458, in warning\r\n self._log(WARNING, msg, args, **kwargs)\r\n File \"/usr/lib/python3.9/logging/init.py\", line 1589, in _log\r\n self.handle(record)\r\n File \"/usr/lib/python3.9/logging/init.py\", line 1599, in handle\r\n self.callHandlers(record)\r\n File \"/usr/lib/python3.9/logging/init.py\", line 1661, in callHandlers\r\n hdlr.handle(record)\r\n File \"/usr/lib/python3.9/logging/init.py\", line 952, in handle\r\n self.emit(record)\r\n File \"/mnt/c/storage/allure_bug/conftest.py\", line 9, in emit\r\n with step(f'[{record.levelname}] {record.getMessage()}'):\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_commons/_allure.py\", line 179, in enter\r\n plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/pluggy/_hooks.py\", line 433, in call\r\n return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/pluggy/_manager.py\", line 112, in _hookexec\r\n return self._inner_hookexec(hook_name, methods, kwargs, firstresult)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py\", line 116, in _multicall\r\n raise exception.with_traceback(exception.traceback)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py\", line 80, in _multicall\r\n res = hook_impl.function(*args)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_pytest/listener.py\", line 48, in start_step\r\n self.allure_logger.start_step(None, uuid, step)\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py\", line 128, in start_step\r\n parent_uuid = parent_uuid if parent_uuid else self._last_executable()\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py\", line 71, in _last_executable\r\n for _uuid in reversed(self._items):\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py\", line 39, in reversed\r\n return self.thread_context.reversed()\r\n File \"/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py\", line 21, in thread_context\r\n uuid, last_item = next(reversed(self._thread_context[self._init_thread].items()))\r\nStopIteration\r\ncollected 1 item\r\n\r\ntest_bug.py test\r\n.\r\n```\r\n\r\n#### If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem\r\n1. Install requirements `pip install pytest allure-pytest`\r\n2. Prepare the demo test suite:\r\n\r\nconftest.py\r\n```python\r\nimport logging\r\nfrom threading import Thread\r\n\r\nfrom allure import step\r\n\r\nclass AllureLoggerHandler(logging.Handler):\r\n def emit(self, record):\r\n with step(f'[{record.levelname}] {record.getMessage()}'):\r\n pass\r\n\r\nlog = logging.getLogger()\r\nallure_handler = AllureLoggerHandler()\r\nlog.addHandler(allure_handler)\r\n\r\ndef _thread():\r\n log.warning('thread')\r\n\r\ndef pytest_generate_tests(metafunc):\r\n log.info('generate')\r\n thread = Thread(target=_thread)\r\n thread.start()\r\n thread.join(100)\r\n```\r\ntest_bug.py\r\n```python\r\ndef test_allure_log():\r\n print('test')\r\n```\r\n3. Run test: `pytest -s --alluredir=./allure`\r\n\r\n#### What is the expected behavior?\r\nTest suite works without any exceptions\r\n\r\n#### What is the motivation / use case for changing the behavior?\r\n\r\n\r\n#### Please tell us about your environment:\r\n\r\n- Allure version: 2.22.0\r\n- Test framework: pytest 7.4.0\r\n- Allure adaptor: allure-pytest 2.13.2\r\n\r\n#### Other information \r\n\r\n[//]: # (\r\n. e.g. detailed explanation, stacktraces, related issues, suggestions \r\n. how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc\r\n)\r\n","author":{"url":"https://github.com/eltimen","@type":"Person","name":"eltimen"},"datePublished":"2023-08-04T20:47:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/757/allure-python/issues/757"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e45bcb4-8abd-0fae-f21f-940db1f770db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B56E:1E5465:42DB92:5BDFD2:696F1D3D |
| html-safe-nonce | bc262f29e796e1cda70de6605901b643854267d2426ace309826b7b8aa19d25f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTZFOjFFNTQ2NTo0MkRCOTI6NUJERkQyOjY5NkYxRDNEIiwidmlzaXRvcl9pZCI6IjkwMzQ5OTEzNzk5OTY5NDE2MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4b02aa149f477411a71456711aa59c2d76f93d7b1ed9e78b787eb26fe3968990 |
| hovercard-subject-tag | issue:1837320649 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/allure-framework/allure-python/757/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55c906f2d4e56d66e5e22a50dcc1a874e0458243ba50377e58a6a5fac30be48d/allure-framework/allure-python/issues/757 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55c906f2d4e56d66e5e22a50dcc1a874e0458243ba50377e58a6a5fac30be48d/allure-framework/allure-python/issues/757 |
| og:image:alt | I'm submitting a ... bug report What is the current behavior? I have a function that creates a thread which writes some information in the log. When I try to call it from pytest_generate_tests allu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eltimen |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/allure-framework/allure-python git https://github.com/allure-framework/allure-python.git |
| octolytics-dimension-user_id | 5879127 |
| octolytics-dimension-user_login | allure-framework |
| octolytics-dimension-repository_id | 79346720 |
| octolytics-dimension-repository_nwo | allure-framework/allure-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 79346720 |
| octolytics-dimension-repository_network_root_nwo | allure-framework/allure-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width