mitmproxy/test/conftest.py

53 lines
1.3 KiB
Python
Raw Normal View History

2017-01-23 21:53:56 +00:00
import os
2016-12-01 09:36:18 +00:00
import pytest
import OpenSSL
import functools
2017-02-06 16:48:44 +00:00
from contextlib import contextmanager
2017-01-23 21:53:56 +00:00
2016-12-01 09:36:18 +00:00
import mitmproxy.net.tcp
2017-02-14 23:27:14 +00:00
pytest_plugins = ('test.full_coverage_plugin',)
2016-12-01 09:36:18 +00:00
requires_alpn = pytest.mark.skipif(
not mitmproxy.net.tcp.HAS_ALPN,
reason='requires OpenSSL with ALPN support')
2017-02-01 15:17:22 +00:00
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'
)
2016-12-01 09:36:18 +00:00
2017-02-14 23:27:14 +00:00
@pytest.fixture()
def disable_alpn(monkeypatch):
monkeypatch.setattr(mitmproxy.net.tcp, 'HAS_ALPN', False)
monkeypatch.setattr(OpenSSL.SSL._lib, 'Cryptography_HAS_ALPN', False)
2017-02-14 23:27:14 +00:00
################################################################################
2017-02-06 16:48:44 +00:00
# TODO: remove this wrapper when pytest 3.1.0 is released
2017-02-14 23:27:14 +00:00
original_pytest_raises = pytest.raises
2017-02-06 16:48:44 +00:00
@contextmanager
2017-02-01 15:48:46 +00:00
@functools.wraps(original_pytest_raises)
def raises(exc, *args, **kwargs):
2017-02-06 16:48:44 +00:00
with original_pytest_raises(exc, *args, **kwargs) as exc_info:
yield
if 'match' in kwargs:
assert exc_info.match(kwargs['match'])
pytest.raises = raises
2017-02-14 23:27:14 +00:00
################################################################################