Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests

Ouverte
#757 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
testing

Piste de recherche

Reproduisez l’échec à l’aide des exemples conftest.py et test_bug.py, en commençant par pytest_generate_tests et le gestionnaire de journalisation threadé. Suivez la création de l’étape Allure présentée dans le traceback et vérifiez le comportement du contexte du thread. C’est terminé lorsque l’exemple s’exécute avec pytest -s --alluredir=./allure sans exception StopIteration.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug theme:core theme:pytest
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 StopIteration exception:

platform linux -- Python 3.9.16, pytest-7.4.0, pluggy-1.2.0
rootdir: /mnt/c/storage/allure_bug
plugins: allure-pytest-2.13.2
collecting ... Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 980, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/c/storage/allure_bug/conftest.py", line 17, in _thread
    log.warning('thread')
  File "/usr/lib/python3.9/logging/init.py", line 1458, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/lib/python3.9/logging/init.py", line 1589, in _log
    self.handle(record)
  File "/usr/lib/python3.9/logging/init.py", line 1599, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.9/logging/init.py", line 1661, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.9/logging/init.py", line 952, in handle
    self.emit(record)
  File "/mnt/c/storage/allure_bug/conftest.py", line 9, in emit
    with step(f'[{record.levelname}] {record.getMessage()}'):
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/_allure.py", line 179, in enter
    plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params)
  File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_hooks.py", line 433, in call
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_manager.py", line 112, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py", line 116, in _multicall
    raise exception.with_traceback(exception.traceback)
  File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py", line 80, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_pytest/listener.py", line 48, in start_step
    self.allure_logger.start_step(None, uuid, step)
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 128, in start_step
    parent_uuid = parent_uuid if parent_uuid else self._last_executable()
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 71, in _last_executable
    for _uuid in reversed(self._items):
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 39, in reversed
    return self.thread_context.reversed()
  File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 21, in thread_context
    uuid, last_item = next(reversed(self._thread_context[self._init_thread].items()))
StopIteration
collected 1 item

test_bug.py test
.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
  1. Install requirements pip install pytest allure-pytest
  2. Prepare the demo test suite:

conftest.py

import logging
from threading import Thread

from allure import step

class AllureLoggerHandler(logging.Handler):
    def emit(self, record):
        with step(f'[{record.levelname}] {record.getMessage()}'):
            pass

log = logging.getLogger()
allure_handler = AllureLoggerHandler()
log.addHandler(allure_handler)

def _thread():
    log.warning('thread')

def pytest_generate_tests(metafunc):
    log.info('generate')
    thread = Thread(target=_thread)
    thread.start()
    thread.join(100)

test_bug.py

def test_allure_log():
    print('test')
  1. Run test: pytest -s --alluredir=./allure
What is the expected behavior?

Test suite works without any exceptions

What is the motivation / use case for changing the behavior?
Please tell us about your environment:
  • Allure version: 2.22.0
  • Test framework: pytest 7.4.0
  • Allure adaptor: allure-pytest 2.13.2
Other information
Langage dominant
Python
Étoiles
819
Forks
261
Merge moyen
3 h 20 min
PR mergées (30 j)
3

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de allure-framework/allure-python

Toutes les issues de allure-framework/allure-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.