Skip to content

Commit

Permalink
Add tests for section_loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Nov 20, 2020
1 parent 89a96b0 commit c0544be
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ jobs:
- tox_env: lint
- tox_env: docs
- tox_env: py36
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: py37
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: py38
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: py39
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: py36-devel
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: py39-devel
PREFIX: PYTEST_REQPASS=416
PREFIX: PYTEST_REQPASS=426
- tox_env: packaging
- tox_env: eco
- tox_env: dockerfile
Expand Down
54 changes: 54 additions & 0 deletions src/molecule/test/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

import logging

import pytest

from molecule.console import should_do_markup
from molecule.logger import get_section_loggers


def test_markup_detection_pycolors0(monkeypatch):
Expand Down Expand Up @@ -59,3 +62,54 @@ class FooLogger(logging.getLoggerClass()):

# this test throws RecursionError prior to bugfix
assert FooLogger("foo")


@pytest.fixture
def _patched_logger_env(request, monkeypatch):
"""Parametrize tests with and without CI env vars."""
envvars = {"CI": None, "GITHUB_ACTIONS": None, "GITLAB_CI": None, "TRAVIS": None}
envvars.update(request.param[1])
for envvar, value in envvars.items():
if value is None:
monkeypatch.delenv(envvar, raising=False)
else:
monkeypatch.setenv(envvar, value)
get_section_loggers.cache_clear()
return request.param[0]


get_section_logger_tests = [
# (expected # of section_loggers, envvars)
(1, {}),
(2, {"CI": "true", "GITHUB_ACTIONS": "true"}),
(2, {"CI": "true", "GITLAB_CI": "true"}),
(2, {"CI": "true", "TRAVIS": "true"}),
(1, {"CI": "true", "RANDOM_CI": "true"}),
]


@pytest.mark.parametrize(
"_patched_logger_env",
get_section_logger_tests,
indirect=True,
)
def test_get_section_loggers(mocker, _patched_ci_env):
expected_section_loggers, _ = _patched_ci_env
section_loggers = get_section_loggers()
assert len(section_loggers) == expected_section_loggers


@pytest.mark.parametrize(
"_patched_logger_env",
get_section_logger_tests,
indirect=True,
)
def test_section_loggers_do_not_change_behavior(mocker, _patched_ci_env):
def dummy():
return True

for wrapper in get_section_loggers():
dummy = wrapper(dummy)

dummy_return = dummy()
assert dummy_return is True

0 comments on commit c0544be

Please sign in to comment.