[pypy-commit] pypy pytest: move the pygame check to the viewer plugin, add a test for it
RonnyPfannschmidt
noreply at buildbot.pypy.org
Tue Oct 2 17:30:00 CEST 2012
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: pytest
Changeset: r57740:3a8ee8860fee
Date: 2012-10-02 17:29 +0200
http://bitbucket.org/pypy/pypy/changeset/3a8ee8860fee/
Log: move the pygame check to the viewer plugin, add a test for it
diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -356,12 +356,6 @@
if getattr(item, '_success', False) and item._pypytest_leaks:
raise leakfinder.MallocMismatch(item._pypytest_leaks)
- if 'pygame' in sys.modules:
- assert option.view, ("should not invoke Pygame "
- "if conftest.option.view is False")
-
-_pygame_imported = False
-
class IntTestFunction(py.test.collect.Function):
def __init__(self, *args, **kwargs):
super(IntTestFunction, self).__init__(*args, **kwargs)
diff --git a/pypy/tool/pytest/test/test_viewerplugin.py b/pypy/tool/pytest/test/test_viewerplugin.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/pytest/test/test_viewerplugin.py
@@ -0,0 +1,28 @@
+import sys
+import pytest
+from pypy.tool.pytest import viewerplugin
+
+class mock:
+ view = False
+
+ @staticmethod
+ def execute():
+ pass
+
+mock.config = mock
+mock.option = mock
+
+
+def test_pygame_teardown_check(monkeypatch):
+ monkeypatch.delitem(sys.modules, 'pygame', raising=False)
+ viewerplugin.pytest_runtest_teardown(mock, mock)
+
+ monkeypatch.setitem(sys.modules, 'pygame', None)
+ with pytest.raises(AssertionError) as exc_info:
+ viewerplugin.pytest_runtest_teardown(mock, mock)
+
+ monkeypatch.setattr(mock, 'view', True)
+ viewerplugin.pytest_runtest_teardown(mock, mock)
+
+
+
diff --git a/pypy/tool/pytest/viewerplugin.py b/pypy/tool/pytest/viewerplugin.py
--- a/pypy/tool/pytest/viewerplugin.py
+++ b/pypy/tool/pytest/viewerplugin.py
@@ -12,7 +12,8 @@
* putting "-p pypy.tool.pytest.viewerplugin"
into pytest.ini
"""
-
+import sys
+import pytest
def pytest_addoption(parser):
@@ -24,3 +25,13 @@
group.addoption('--viewloops', action="store_true",
default=False, dest="viewloops",
help="show only the compiled loops")
+
+
+ at pytest.mark.tryfirst
+def pytest_runtest_teardown(__multicall__, item):
+ __multicall__.execute()
+
+ if 'pygame' in sys.modules:
+ assert item.config.option.view, ("should not invoke Pygame "
+ "if view option is False")
+
More information about the pypy-commit
mailing list