File: conftest.py

package info (click to toggle)
python-dugong 3.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 548 kB
  • ctags: 388
  • sloc: python: 2,205; makefile: 20; sh: 1
file content (65 lines) | stat: -rw-r--r-- 2,497 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import os.path
import logging
import pytest

if sys.version_info < (3,3):
    raise SystemExit('Python version is %d.%d.%d, but Dugong requires 3.3 or newer'
                     % sys.version_info[:3])

# Converted to autouse fixture below if capture is activated
def check_test_output(request, capfd):
    request.capfd = capfd
    def raise_on_exception_in_out():
        # Peek at captured output
        (stdout, stderr) = capfd.readouterr()
        sys.stdout.write(stdout)
        sys.stderr.write(stderr)

        if ('exception' in stderr.lower()
            or 'exception' in stdout.lower()):
            raise AssertionError('Suspicious output to stderr')

    request.addfinalizer(raise_on_exception_in_out)


def pytest_addoption(parser):
    group = parser.getgroup("general")
    group._addoption("--installed", action="store_true", default=False,
                     help="Test the installed package.")

    group = parser.getgroup("terminal reporting")
    group._addoption("--logdebug", action="store_true", default=False,
                     help="Activate debugging output.")

def pytest_configure(config):
    # Enable stdout and stderr analysis, unless output capture is disabled
    if config.getoption('capture') != 'no':
        global check_test_output
        check_test_output = pytest.fixture(autouse=True)(check_test_output)

    # If we are running from the source directory, make sure that we load
    # modules from here
    basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if not config.getoption('installed'):
        if (os.path.exists(os.path.join(basedir, 'setup.py')) and
            os.path.exists(os.path.join(basedir, 'dugong', '__init__.py'))):
            sys.path.insert(0, basedir)

    # When running from HG repo, enable all warnings
    if os.path.exists(os.path.join(basedir, '.hg')):
        import warnings
        warnings.resetwarnings()
        warnings.simplefilter('error')

    logdebug = config.getoption('logdebug')
    if logdebug:
        root_logger = logging.getLogger()
        formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(threadName)s '
                                      '%(funcName)s: %(message)s',
                                      datefmt="%H:%M:%S")
        handler = logging.StreamHandler(sys.stdout)
        handler.setLevel(logging.DEBUG)
        handler.setFormatter(formatter)
        root_logger.addHandler(handler)
        root_logger.setLevel(logging.DEBUG)