aboutsummaryrefslogtreecommitdiffstats
path: root/test/conftest.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2017-02-06 17:48:44 +0100
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2017-02-08 20:04:07 +0100
commit7a9d40817ce0a97317b7940f7da2bb64da02eb51 (patch)
tree10447e8bf5d9ca3a53c03ed48a371662dfc52218 /test/conftest.py
parent28c0596742674dd59df317a91389f3826b7d5e66 (diff)
downloadmitmproxy-7a9d40817ce0a97317b7940f7da2bb64da02eb51.tar.gz
mitmproxy-7a9d40817ce0a97317b7940f7da2bb64da02eb51.tar.bz2
mitmproxy-7a9d40817ce0a97317b7940f7da2bb64da02eb51.zip
pytest.raises: shim new API
Diffstat (limited to 'test/conftest.py')
-rw-r--r--test/conftest.py29
1 files changed, 7 insertions, 22 deletions
diff --git a/test/conftest.py b/test/conftest.py
index 4b05624b..50ec3421 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -2,6 +2,7 @@ import os
import pytest
import OpenSSL
import functools
+from contextlib import contextmanager
import mitmproxy.net.tcp
@@ -29,35 +30,19 @@ skip_appveyor = pytest.mark.skipif(
original_pytest_raises = pytest.raises
+# TODO: remove this wrapper when pytest 3.1.0 is released
+@contextmanager
@functools.wraps(original_pytest_raises)
def raises(exc, *args, **kwargs):
- if isinstance(exc, str):
- return RaisesContext(exc)
- else:
- return original_pytest_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
-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)