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 does not capture teardown logs if a fixture throws an exception #12203

Open
3 of 4 tasks
dcermak opened this issue Apr 10, 2024 · 0 comments
Open
3 of 4 tasks

Pytest does not capture teardown logs if a fixture throws an exception #12203

dcermak opened this issue Apr 10, 2024 · 0 comments

Comments

@dcermak
Copy link

dcermak commented Apr 10, 2024

I have a pyest plugin (https://github.com/dcermak/pytest_container) that provides multiple fixtures which perform some heavy lifting (container launching). The plugin performs roughly the following action in the fixtures (simplified version, the actual implementation is here: https://github.com/dcermak/pytest_container/blob/c7f1623da7947c53768dd49f1a440a525e02948d/pytest_container/plugin.py#L67):

def fixture(request):
    with Launcher(request.param[0]) as launcher:
        try:
            launcher.start_container()
        except:
            _logger.debug("failed to start container, got log: %s", get_ctr_log())
            raise

However, pytest does not capture the log output from my plugin if an exception is actually thrown. It does capture stdout, but I would prefer to be able to use the logger for everything for the sake of consistency.

pip list

Package              Version
-------------------- ------------------------------
bci-tester           0.1.dev1205+g58f5b61.d20240410
certifi              2024.2.2
charset-normalizer   3.3.2
deprecation          2.1.0
execnet              2.1.1
filelock             3.13.4
idna                 3.6
iniconfig            2.0.0
packaging            24.0
pip                  23.2.1
pluggy               1.4.0
psycopg2             2.9.9
PyMySQL              1.1.0
pytest               8.1.1
pytest_container     0.4.2
pytest-rerunfailures 14.0
pytest-testinfra     10.1.0
pytest-xdist         3.5.0
requests             2.31.0
tenacity             8.2.3
typing_extensions    4.11.0
urllib3              2.2.1

pytest & os version

pytest 8.1.1
Fedora 39

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible
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

No branches or pull requests

1 participant