From ec92d7f67e3c5960d9b30e067fb4ed1ae3fc8884 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 1 Feb 2017 16:17:22 +0100 Subject: cleanup test utils --- test/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index 4d779b01..3f623c51 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -9,6 +9,21 @@ 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): -- cgit v1.2.3 From ae008ed80b870688e4e0fe5ff305dc40c17458b4 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 1 Feb 2017 16:48:46 +0100 Subject: replace tutils.raises with pytest.raises + shim --- test/conftest.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index 3f623c51..ef262944 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,7 @@ import os import pytest import OpenSSL +import functools import mitmproxy.net.tcp @@ -25,6 +26,38 @@ skip_appveyor = pytest.mark.skipif( ) +original_pytest_raises = pytest.raises + + +def raises(exc, *args, **kwargs): + functools.wraps(original_pytest_raises) + if isinstance(exc, str): + return RaisesContext(exc) + else: + return original_pytest_raises(exc, *args, **kwargs) + + +pytest.raises = raises + + +class RaisesContext: + def __init__(self, expected_exception): + self.expected_exception = expected_exception + + def __enter__(self): + return + + def __exit__(self, exc_type, exc_val, exc_tb): + if not exc_type: + raise AssertionError("No exception raised.") + else: + if self.expected_exception.lower() not in str(exc_val).lower(): + raise AssertionError( + "Expected %s, but caught %s" % (repr(self.expected_exception), repr(exc_val)) + ) + return True + + @pytest.fixture() def disable_alpn(monkeypatch): monkeypatch.setattr(mitmproxy.net.tcp, 'HAS_ALPN', False) -- cgit v1.2.3 From 4f0b2bc4dec4eb3c4f0075bcebebeb126a5a6e88 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 2 Feb 2017 14:20:56 +0100 Subject: adapt coverage checks --- test/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index ef262944..c44aa461 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -116,7 +116,7 @@ def pytest_runtestloop(session): prefix = os.getcwd() excluded_files = [os.path.normpath(f) for f in pytest.config.option.no_full_cov] measured_files = [os.path.normpath(os.path.relpath(f, prefix)) for f in cov.get_data().measured_files()] - measured_files = [f for f in measured_files if f not in excluded_files] + measured_files = [f for f in measured_files if not any(f.startswith(excluded_f) for excluded_f in excluded_files)] for name in pytest.config.option.full_cov: files = [f for f in measured_files if f.startswith(os.path.normpath(name))] -- cgit v1.2.3