diff --git a/pytestqt/qt_compat.py b/pytestqt/qt_compat.py index 22f0bf88..796ebaaf 100644 --- a/pytestqt/qt_compat.py +++ b/pytestqt/qt_compat.py @@ -31,7 +31,7 @@ def _get_qt_api_from_env(self): api = api.lower() if api not in ('pyside', 'pyqt4', 'pyqt4v2', 'pyqt5'): # pragma: no cover msg = 'Invalid value for $PYTEST_QT_API: %s' - raise RuntimeError(msg % qt_api) + raise RuntimeError(msg % api) return api def _guess_qt_api(self): # pragma: no cover diff --git a/tests/test_basics.py b/tests/test_basics.py index 835c2fab..fddac5c3 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -349,7 +349,30 @@ def test_foo(qtbot): '* 1 passed in *' ]) else: - result.stderr.fnmatch_lines([ - '*ImportError:*' - ]) + try: + ModuleNotFoundError + except NameError: + # Python < 3.6 + result.stderr.fnmatch_lines([ + '*ImportError:*' + ]) + else: + # Python >= 3.6 + result.stderr.fnmatch_lines([ + '*ModuleNotFoundError:*' + ]) + + +def test_invalid_qt_api_envvar(testdir, monkeypatch): + """ + Make sure the error message with an invalid PYQTEST_QT_API is correct. + """ + testdir.makepyfile(''' + import pytest + def test_foo(qtbot): + pass + ''') + monkeypatch.setenv('PYTEST_QT_API', 'piecute') + result = testdir.runpytest_subprocess() + result.stderr.fnmatch_lines(['* Invalid value for $PYTEST_QT_API: piecute'])