aboutsummaryrefslogtreecommitdiffstats
path: root/test/conftest.py
blob: b4e1da932304ce4bacc345cbcadb4f17a04cc887 (plain)
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
import os
import pytest
import OpenSSL
import functools
from contextlib import contextmanager

import mitmproxy.net.tcp

pytest_plugins = ('test.full_coverage_plugin',)

requires_alpn = pytest.mark.skipif(
    not mitmproxy.net.tcp.HAS_ALPN,
    reason='requires OpenSSL with ALPN support')

skip_windows = pytest.mark.skipif(
    os.name == "nt",
    reason='Skipping due to Windows'
)

skip_not_windows = pytest.mark.skipif(
    os.name != "nt",
    reason='Skipping due to not Windows'
)

skip_appveyor = pytest.mark.skipif(
    "APPVEYOR" in os.environ,
    reason='Skipping due to Appveyor'
)


@pytest.fixture()
def disable_alpn(monkeypatch):
    monkeypatch.setattr(mitmproxy.net.tcp, 'HAS_ALPN', False)
    monkeypatch.setattr(OpenSSL.SSL._lib, 'Cryptography_HAS_ALPN', False)


################################################################################
# TODO: remove this wrapper when pytest 3.1.0 is released
original_pytest_raises = pytest.raises


@contextmanager
@functools.wraps(original_pytest_raises)
def raises(exc, *args, **kwargs):
    with original_pytest_raises(exc, *args, **kwargs) as exc_info:
        yield
    if 'match' in kwargs:
        assert exc_info.match(kwargs['match'])


pytest.raises = raises
################################################################################