Skip to content

Commit

Permalink
FEAT(PYTEST) +--logger-disabled CLI ...
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Jun 29, 2020
1 parent 85a6b9d commit 174e9cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
29 changes: 29 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from collections import namedtuple
from multiprocessing import Pool
Expand Down Expand Up @@ -30,6 +31,34 @@
# See https://stackoverflow.com/questions/33508060/create-and-import-helper-functions-in-tests-without-creating-packages-in-test-di
collect_ignore = ["helpers.py"]

########
## From https://stackoverflow.com/a/57002853/548792
##
def pytest_addoption(parser):
"""Add a command line option to disable logger."""
parser.addoption(
"--logger-disabled",
action="append",
default=[],
help="disable specific loggers",
)


def pytest_configure(config):
"""Disable the loggers from CLI and silence sphinx markers warns."""
for name in config.getoption("--logger-disabled", default=[]):
logger = logging.getLogger(name)
logger.propagate = False

config.addinivalue_line("markers", "sphinx: parametrized sphinx test-launches")
config.addinivalue_line(
"markers", "test_params: for parametrized sphinx test-launches"
)


##
########


@pytest.fixture
def debug_mode():
Expand Down
7 changes: 0 additions & 7 deletions test/sphinxext/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,3 @@ def _initialize_test_directory(session):

def pytest_sessionstart(session):
_initialize_test_directory(session)


def pytest_configure(config):
config.addinivalue_line("markers", "sphinx: parametrized sphinx test-launches")
config.addinivalue_line(
"markers", "test_params: for parametrized sphinx test-launches"
)

0 comments on commit 174e9cb

Please sign in to comment.