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

labgrid: pytestplugin: hooks: fix multiple start stop for StepLogger #1474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions labgrid/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def flush(self):


class StepLogger:
_started = False
started = False
_logger = None
_serial_logger = None
_length_limit = 100
Expand All @@ -144,21 +144,21 @@ def __attrs_post_init__(self):
@classmethod
def start(cls, length_limit=None):
"""starts the StepLogger"""
assert not cls._started
assert not cls.started
if cls._logger is None:
cls._logger = logging.getLogger("StepLogger")
steps.subscribe(cls.notify)
cls._serial_logger = SerialLoggingReporter()
cls._started = True
cls.started = True
if length_limit is not None:
cls._length_limit = length_limit

@classmethod
def stop(cls):
"""stops the StepLogger"""
assert cls._started
assert cls.started
steps.unsubscribe(cls.notify)
cls._started = False
cls.started = False

@classmethod
def get_prefix(cls, event):
Expand Down
5 changes: 3 additions & 2 deletions labgrid/pytestplugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def configure_pytest_logging(config, plugin):

@pytest.hookimpl(trylast=True)
def pytest_configure(config):
StepLogger.start()
config.add_cleanup(StepLogger.stop)
if not StepLogger.started:
StepLogger.start()
config.add_cleanup(StepLogger.stop)

logging_plugin = config.pluginmanager.getplugin('logging-plugin')
if logging_plugin:
Expand Down
Loading