[pypy-commit] pypy py3tests: Add minimal fixture implementation for untranslated apptests

rlamy pypy.commits at gmail.com
Fri Mar 23 07:32:10 EDT 2018


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3tests
Changeset: r94115:9daca42128ef
Date: 2018-03-23 12:16 +0100
http://bitbucket.org/pypy/pypy/changeset/9daca42128ef/

Log:	Add minimal fixture implementation for untranslated apptests

diff --git a/pypy/tool/pytest/apptest2.py b/pypy/tool/pytest/apptest2.py
--- a/pypy/tool/pytest/apptest2.py
+++ b/pypy/tool/pytest/apptest2.py
@@ -82,8 +82,14 @@
 
     def execute_appex(self, space, w_func):
         space.getexecutioncontext().set_sys_exc_info(None)
+        sig = w_func.code._signature
+        if sig.varargname or sig.kwargname or sig.kwonlyargnames:
+            raise ValueError(
+                'Test functions may not use *args, **kwargs or '
+                'keyword-only args')
+        args_w = self.get_fixtures(space, sig.argnames)
         try:
-            space.call_function(w_func)
+            space.call_function(w_func, *args_w)
         except OperationError as e:
             if self.config.option.raise_operr:
                 raise
@@ -99,3 +105,15 @@
         """Must return a triple (fspath, lineno, test_name)"""
         lineno = self.w_obj.code.co_firstlineno
         return self.parent.fspath, lineno, self.w_obj.name
+
+    def get_fixtures(self, space, fixtures):
+        if not fixtures:
+            return []
+        import imp
+        fixtures_mod = imp.load_source(
+            'fixtures', str(self.parent.fspath.new(basename='fixtures.py')))
+        result = []
+        for name in fixtures:
+            arg = getattr(fixtures_mod, name)(space, self.parent.config)
+            result.append(arg)
+        return result
diff --git a/pypy/tool/pytest/fake_pytest/__init__.py b/pypy/tool/pytest/fake_pytest/__init__.py
--- a/pypy/tool/pytest/fake_pytest/__init__.py
+++ b/pypy/tool/pytest/fake_pytest/__init__.py
@@ -5,6 +5,7 @@
     interpleveldefs = {
         'raises': 'interp_pytest.pypyraises',
         'skip': 'interp_pytest.pypyskip',
+        'fixture': 'interp_pytest.fake_fixture',
     }
     appleveldefs = {
         'importorskip': 'app_pytest.importorskip',
diff --git a/pypy/tool/pytest/fake_pytest/interp_pytest.py b/pypy/tool/pytest/fake_pytest/interp_pytest.py
--- a/pypy/tool/pytest/fake_pytest/interp_pytest.py
+++ b/pypy/tool/pytest/fake_pytest/interp_pytest.py
@@ -1,1 +1,4 @@
 from pypy.tool.pytest.appsupport import pypyraises, pypyskip
+
+def fake_fixture(space, w_arg):
+    return w_arg


More information about the pypy-commit mailing list