diff --git a/html5lib/tests/conftest.py b/html5lib/tests/conftest.py index ce93eff6..dad167c5 100644 --- a/html5lib/tests/conftest.py +++ b/html5lib/tests/conftest.py @@ -1,4 +1,6 @@ +from __future__ import print_function import os.path +import sys import pkg_resources import pytest @@ -15,6 +17,26 @@ _sanitizer_testdata = os.path.join(_dir, "sanitizer-testdata") +def fail_if_missing_pytest_expect(): + """Throws an exception halting pytest if pytest-expect isn't working""" + try: + from pytest_expect import expect # noqa + except ImportError: + header = '*' * 78 + print( + '\n' + + header + '\n' + + 'ERROR: Either pytest-expect or its dependency u-msgpack-python is not\n' + + 'installed. Please install them both before running pytest.\n' + + header + '\n', + file=sys.stderr + ) + raise + + +fail_if_missing_pytest_expect() + + def pytest_configure(config): msgs = []