Skip to content

test: unify logger output mocking #1797

@efiop

Description

@efiop

Currently, when we want to check stderr/stdout we need to do a lot of different actions like

from tests.utils import reset_logger_error_output, reset_logger_standard_output
from tests.utils.logger import MockLoggerHandlers, ConsoleFontColorsRemove
...
        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_error_output()
            ...
            self.assertIn(
                "unable to read stage file: {} "
                "YAML file structure is corrupted".format(foo_stage),
                logger.handlers[1].stream.getvalue(),
            )

from https://github.com/iterative/dvc/blob/0.32.1/tests/test_add.py .

which is way too many actions to simply check for stderr output. It seems like we could do better than that by unifying all of this into something like:

    with MockStderr as stderr:
       self.assertEqual(stderr, "expected")

without having to import a bunch of stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhances DVCp2-mediumMedium priority, should be done, but less important

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions