Title: KeyError in allure_pytest when running pytest.main() from inside a test (nested pytest run) · Issue #881 · allure-framework/allure-python · GitHub
Open Graph Title: KeyError in allure_pytest when running pytest.main() from inside a test (nested pytest run) · Issue #881 · allure-framework/allure-python
X Title: KeyError in allure_pytest when running pytest.main() from inside a test (nested pytest run) · Issue #881 · allure-framework/allure-python
Description: Running a nested pytest session (subsession) from within a test using pytest.main() causes allure to fail during teardown in subsession with a KeyError in allure_commons/reporter.py. The inner test passes, but allure raises an exception,...
Open Graph Description: Running a nested pytest session (subsession) from within a test using pytest.main() causes allure to fail during teardown in subsession with a KeyError in allure_commons/reporter.py. The inner test...
X Description: Running a nested pytest session (subsession) from within a test using pytest.main() causes allure to fail during teardown in subsession with a KeyError in allure_commons/reporter.py. The inner test...
Opengraph URL: https://github.com/allure-framework/allure-python/issues/881
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"KeyError in allure_pytest when running pytest.main() from inside a test (nested pytest run)","articleBody":"Running a nested pytest session (subsession) from within a test using `pytest.main()` causes `allure` to fail during teardown in subsession with a `KeyError` in `allure_commons/reporter.py`.\nThe inner test passes, but `allure` raises an exception, causing the overall main test to fail.\n\nThe issue reproduces **only** when both main and sub sessions use allure (for example, via configuration (`pytest.ini` or `pyproject.toml`) and the subsession runs teardown fixtures.\n\nThe report shows the subtest as broken and duplicates teardown fixtures for it - one fixture has `passed` state, and the duplicate has `unknown` state. \n\n| simple_fixture::0 | Unknown |\n|-|-|\n| simple_fixture::0 | 0s|\n\nOverriding `alluredir` doesn't help - allure report for main session always contains both tests, allure report for subsession - only its test.\n\nSteps to reproduce:\n1. Set pytest ini options (I'm using `pyproject.toml`)\n```toml\n[tool.pytest.ini_options]\naddopts = [\n \"-v\",\n \"--alluredir\", \"allure-results\",\n]\n```\n2. Create test file\n\n```python\nfrom pathlib import Path\n\nimport pytest\n\n\ndef test_parent():\n args: list[str] = [\n f\"{Path(__file__)}::test_child\",\n ]\n result = pytest.main(args)\n assert not result\n\n\n@pytest.fixture()\ndef simple_fixture():\n yield 2\n\n\ndef test_child(simple_fixture):\n assert simple_fixture == 2\n\n```\n3. Run the command\n```bash\npytest test/test_parent.py::test_parent\n```\n\nActual result:\n```log\n❯ poetry run pytest test/test_parent.py::test_parent\n======================================== test session starts =========================================\nplatform darwin -- Python 3.13.5, pytest-8.4.0, pluggy-1.6.0 -- /example_dir/Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/bin/python\ncachedir: .pytest_cache\nrootdir: /example_dir/tests_repo\nconfigfile: pyproject.toml\nplugins: allure-pytest-2.14.2, xdist-3.7.0, instafail-0.5.0, anyio-4.9.0, timeout-2.4.0, check-2.5.3, mock-3.14.1, cov-6.1.1\ncollected 1 item\n\ntest/test_parent.py::test_parent FAILED [100%]\n\n============================================== FAILURES ==============================================\n____________________________________________ test_parent _____________________________________________\n\n def test_parent():\n args: list[str] = [\n \"-s\",\n f\"{Path(__file__)}::test_child\",\n ]\n result = pytest.main(args)\n\u003e assert not result\nE assert not \u003cExitCode.TESTS_FAILED: 1\u003e\n\ntest/test_parent.py:12: AssertionError\n---------------------------------------- Captured stdout call ----------------------------------------\n============================= test session starts ==============================\nplatform darwin -- Python 3.13.5, pytest-8.4.0, pluggy-1.6.0 -- /example_dir/Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/bin/python\ncachedir: .pytest_cache\nrootdir: /example_dir/tests_repo\nconfigfile: pyproject.toml\nplugins: allure-pytest-2.14.2, xdist-3.7.0, instafail-0.5.0, anyio-4.9.0, timeout-2.4.0, check-2.5.3, mock-3.14.1, cov-6.1.1\ncollecting ... collected 1 item\n\ntest/test_parent.py::test_child PASSED\ntest/test_parent.py::test_child ERROR\n\n==================================== ERRORS ====================================\n_______________________ ERROR at teardown of test_child ________________________\n\nself = \u003callure_commons._allure.fixture object at 0x1027574d0\u003e, args = ()\nkwargs = {}\n\n def __call__(self, *args, **kwargs):\n self.parameters = func_parameters(self._fixture_function, *args, **kwargs)\n\n\u003e with self:\n ^^^^\n\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_commons/_allure.py:230:\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_commons/_allure.py:240: in __exit__\n plugin_manager.hook.stop_fixture(parent_uuid=self._parent_uuid,\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_pytest/listener.py:66: in stop_fixture\n self.allure_logger.stop_after_fixture(uuid,\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_commons/reporter.py:109: in stop_after_fixture\n self._update_item(uuid, **kwargs)\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_commons/reporter.py:62: in _update_item\n item = self._items[uuid] if uuid else self._items[next(reversed(self._items))]\n ^^^^^^^^^^^^^^^^^\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n\nself = \u003callure_commons.reporter.ThreadContextItems object at 0x10264b4d0\u003e\nitem = '5073499a-d95d-40a6-a635-36507b26b451'\n\n def __getitem__(self, item):\n\u003e return self.thread_context.__getitem__(item)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nE KeyError: '5073499a-d95d-40a6-a635-36507b26b451'\n\n../../Library/Caches/pypoetry/virtualenvs/tests_repo-CJ2ygyH8-py3.13/lib/python3.13/site-packages/allure_commons/reporter.py:33: KeyError\n=========================== short test summary info ============================\nERROR test/test_parent.py::test_child - KeyError: '5073499a-d95d-40a6-a635-36...\n========================== 1 passed, 1 error in 0.05s ==========================\n====================================== short test summary info =======================================\nFAILED test/test_parent.py::test_parent - assert not \u003cExitCode.TESTS_FAILED: 1\u003e\n========================================= 1 failed in 0.14s ==========================================\n```","author":{"url":"https://github.com/sashko1988","@type":"Person","name":"sashko1988"},"datePublished":"2025-10-09T16:15:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/881/allure-python/issues/881"}
| 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:6ad319de-6352-62a5-39b4-0a9d0ae2791d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0AC:A9627:56C651:792492:696E5AFC |
| html-safe-nonce | 2fe2eeb0ec1d3bdb3233d5798624a8f33484590c7cb3d36240f32eb69b7a836d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEFDOkE5NjI3OjU2QzY1MTo3OTI0OTI6Njk2RTVBRkMiLCJ2aXNpdG9yX2lkIjoiMjA2NDU3MDI2Mzg5NzI2Njk0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 29a89bdb7a1fc4bd9fa3ee5fd7f306f56ceb1674c983d5da10e45c44234d25dc |
| hovercard-subject-tag | issue:3499798480 |
| 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/881/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e9a59b88a1ab3ad8bcc117809238a1ebfd07a7f9814f669c837a3440b6968657/allure-framework/allure-python/issues/881 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e9a59b88a1ab3ad8bcc117809238a1ebfd07a7f9814f669c837a3440b6968657/allure-framework/allure-python/issues/881 |
| og:image:alt | Running a nested pytest session (subsession) from within a test using pytest.main() causes allure to fail during teardown in subsession with a KeyError in allure_commons/reporter.py. The inner test... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sashko1988 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f68b42d371252b0f236260d6234f4304a806fe5ac43d59faa21fb59d80df103b |
| 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 | 6b74bc8dbcd10b5d69fd9ee9d2cfdc8b35e18a4c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width