Completed
Pull Request — develop (#141)
by Jace
04:10
created

QuietReporter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 10
wmc 1
1
"""Unit test configuration file."""
2
3
import os
4
import logging
5
6
import pytest
7
import yorm
8
9
10
ENV = 'TEST_INTEGRATION'  # environment variable to enable integration tests
11
REASON = "'{0}' variable not set".format(ENV)
12
13
ROOT = os.path.dirname(__file__)
14
FILES = os.path.join(ROOT, 'files')
15
16
17
def pytest_configure(config):
18
    """Conigure logging and silence verbose test runner output."""
19
    logging.basicConfig(
20
        level=logging.DEBUG,
21
        format="[%(levelname)-8s] (%(name)s @%(lineno)4d) %(message)s",
22
    )
23
    logging.getLogger('yorm').setLevel(logging.WARNING)
24
25
    terminal = config.pluginmanager.getplugin('terminal')
26
27
    class QuietReporter(terminal.TerminalReporter):
28
29
        def __init__(self, *args, **kwargs):
30
            super().__init__(*args, **kwargs)
31
            self.verbosity = 0
32
            self.showlongtestinfo = False
33
            self.showfspath = False
34
35
    terminal.TerminalReporter = QuietReporter
36
37
38
def pytest_runtest_setup(item):
39
    """Disable YORM file storage during unit tests."""
40
    if 'integration' in item.keywords:
41
        if not os.getenv(ENV):
42
            pytest.skip(REASON)
43
        else:
44
            yorm.settings.fake = False
45
    else:
46
        yorm.settings.fake = True
47