Skip to content

Logging after yield causes a crash #4500

@oscar-bray-sl

Description

@oscar-bray-sl

OS: linux ubuntu 18.04.1
Pytest version: 4.0.1

If you use the python logging library and log something during teardown, it causes a crash if the teardown runs due to cancelling the test e.g. using ctrl-c and causing a keyboard interrupt.
This is a new bug in pytest 4.0, if I run it with 3.9 it works fine.

https://stackoverflow.com/questions/53591387/pytest-error-in-teardown-when-using-logging

yield something
logging.info("it crashes due to this but only if you cancel the test")
print ("that means this isn't printed and nothing past here runs")

The error you get is this:
File "/home/oscar/.local/lib/python3.6/site-packages/_pytest/capture.py", line 167, in global_and_fixture_disabled
self.resume_global_capture()
File "/home/oscar/.local/lib/python3.6/site-packages/_pytest/capture.py", line 120, in resume_global_capture
self._global_capturing.resume_capturing()
AttributeError: 'NoneType' object has no attribute 'resume_capturing'

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: loggingrelated to the logging builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions