Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.6
Changeset: r98565:b195c68558a4
Date: 2020-01-21 03:41 +0000
http://bitbucket.org/pypy/pypy/changeset/b195c68558a4/

Log:    Add @pytest.mark.pypy_only to simplify skipping PyPy-specific app-
        level tests on CPython

diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -68,6 +68,9 @@
     if not mode_A and not mode_D:  # 'own' tests
         from rpython.conftest import LeakFinder
         config.pluginmanager.register(LeakFinder())
+    if mode_A:
+        from pypy.tool.pytest.apptest import PythonInterpreter
+        config.applevel = PythonInterpreter(config.option.python)
 
 def pytest_addoption(parser):
     group = parser.getgroup("pypy options")
@@ -201,13 +204,16 @@
 @pytest.hookimpl(tryfirst=True)
 def pytest_runtest_setup(item):
     if isinstance(item, py.test.collect.Function):
+        config = item.config
+        if item.get_marker(name='pypy_only') and not config.applevel.is_pypy:
+            pytest.skip('PyPy-specific test')
         appclass = item.getparent(py.test.Class)
         if appclass is not None:
             from pypy.tool.pytest.objspace import gettestobjspace
             # Make cls.space and cls.runappdirect available in tests.
             spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
             appclass.obj.space = gettestobjspace(**spaceconfig)
-            appclass.obj.runappdirect = option.runappdirect
+            appclass.obj.runappdirect = config.option.runappdirect
 
 def pytest_ignore_collect(path, config):
     if (config.getoption('direct_apptest') and not path.isdir()
diff --git a/pypy/interpreter/test/test_argument.py 
b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -806,7 +806,7 @@
         exc = raises(TypeError, '(lambda *, kw: 0)(1, kw=3)')
         assert str(exc.value) == "<lambda>() takes 0 positional arguments but 
1 positional argument (and 1 keyword-only argument) were given"
 
-    @py.test.mark.skipif("config.option.runappdirect")
+    @pytest.mark.pypy_only
     def test_error_message_method(self):
         class A(object):
             def f0():
@@ -823,14 +823,14 @@
         # does not contain the warning about missing self
         assert exc.value.args[0] == "f0() takes 0 positional arguments but 1 
was given"
 
-    @py.test.mark.skipif("config.option.runappdirect")
+    @pytest.mark.pypy_only
     def test_error_message_module_function(self):
         import operator # use countOf because it's defined at applevel
         exc = raises(TypeError, lambda : operator.countOf(1, 2, 3))
         # does not contain the warning about missing self
         assert exc.value.args[0] == "countOf() takes 2 positional arguments 
but 3 were given"
 
-    @py.test.mark.skipif("config.option.runappdirect")
+    @pytest.mark.pypy_only
     def test_error_message_bound_method(self):
         class A(object):
             def f0():
diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py
--- a/pypy/tool/pytest/apptest.py
+++ b/pypy/tool/pytest/apptest.py
@@ -35,6 +35,24 @@
     def __init__(self, excinfo):
         self.excinfo = excinfo
 
+class PythonInterpreter(object):
+    def __init__(self, path):
+        self.path = path
+        self._is_pypy = None
+
+    @property
+    def is_pypy(self):
+        if self._is_pypy is not None:
+            return self._is_pypy
+        CODE = "import sys; print('__pypy__' in sys.builtin_module_names)"
+        res, stdout, stderr = run_subprocess( self.path, ["-c", CODE])
+        if res != 0:
+            raise ValueError("Invalid Python interpreter")
+        print stdout
+        is_pypy = stdout.strip() == 'True'
+        self._is_pypy = is_pypy
+        return is_pypy
+
 
 def py3k_repr(value):
     "return the repr() that py3k would give for an object."""
@@ -120,7 +138,7 @@
                 pytest.fail("DID NOT RAISE")
             self.value = tp[1]
             return issubclass(tp[0], self.expected_exception)
-    
+
     __builtins__.raises = raises
     class Test:
         pass
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to