Completed
Pull Request — master (#68)
by Jace
03:27
created

pytest_runtest_setup()   B

Complexity

Conditions 7

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 7
c 5
b 0
f 0
dl 0
loc 8
rs 7.3333
1
"""Unit test configuration file."""
2
3
import os
4
import platform
5
import logging
6
7
import pytest
8
9
ENV = 'TEST_INTEGRATION'  # environment variable to enable integration tests
10
REASON = "'{0}' variable not set".format(ENV)
11
12
ROOT = os.path.dirname(__file__)
13
FILES = os.path.join(ROOT, 'files')
14
15
16
def pytest_configure(config):
17
    """Disable verbose output when running tests."""
18
    logging.basicConfig(
19
        level=logging.DEBUG,
20
        format="[%(levelname)-8s] (%(name)s @%(lineno)4d) %(message)s",
21
    )
22
    logging.getLogger('yorm').setLevel(logging.WARNING)
23
24
    terminal = config.pluginmanager.getplugin('terminal')
25
    base = terminal.TerminalReporter
26
27
    class QuietReporter(base):
28
        """A py.test reporting that only shows dots when running tests."""
29
30
        def __init__(self, *args, **kwargs):
31
            super().__init__(*args, **kwargs)
32
            self.verbosity = 0
33
            self.showlongtestinfo = False
34
            self.showfspath = False
35
36
    terminal.TerminalReporter = QuietReporter
37
38
39
def pytest_runtest_setup(item):
40
    """pytest setup."""
41
    if 'linux_only' in item.keywords and platform.system() != 'Linux':
42
        pytest.skip("test can only be run on Linux")
43
    if 'mac_only' in item.keywords and platform.system() != 'Darwin':
44
        pytest.skip("test can only be run on OS X")
45
    if 'windows_only' in item.keywords and platform.system() != 'Windows':
46
        pytest.skip("test can only be run on Windows")
47
48
49
@pytest.fixture
50
def path(tmpdir):
51
    """Figure to create a temporary settings file path."""
52
    tmpdir.chdir()
53
    return tmpdir.join('custom.ext').strpath
54