[pypy-commit] pypy default: Allow per-test parametrisation of the space fixture
rlamy
pypy.commits at gmail.com
Thu Sep 26 10:57:05 EDT 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r97618:f5fae9818da9
Date: 2019-09-26 15:48 +0100
http://bitbucket.org/pypy/pypy/changeset/f5fae9818da9/
Log: Allow per-test parametrisation of the space fixture
diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -72,10 +72,13 @@
default=False, dest="applevel_rewrite",
help="Use assert rewriting in app-level test files (slow)")
+ at pytest.fixture(scope='class')
+def spaceconfig(request):
+ return getattr(request.cls, 'spaceconfig', {})
+
@pytest.fixture(scope='function')
-def space(request):
+def space(spaceconfig):
from pypy.tool.pytest.objspace import gettestobjspace
- spaceconfig = getattr(request.cls, 'spaceconfig', {})
return gettestobjspace(**spaceconfig)
diff --git a/pypy/module/_multiprocessing/test/test_interp_semaphore.py b/pypy/module/_multiprocessing/test/test_interp_semaphore.py
--- a/pypy/module/_multiprocessing/test/test_interp_semaphore.py
+++ b/pypy/module/_multiprocessing/test/test_interp_semaphore.py
@@ -1,3 +1,4 @@
+import pytest
import time
from rpython.rlib.rgil import yield_thread
from pypy.tool.pytest.objspace import gettestobjspace
@@ -7,8 +8,9 @@
from pypy.module._multiprocessing.interp_semaphore import (
create_semaphore, sem_unlink, W_SemLock)
+ at pytest.mark.parametrize('spaceconfig', [
+ {'usemodules': ['_multiprocessing', 'thread']}])
def test_stuff(space):
- space = gettestobjspace(usemodules=['_multiprocessing', 'thread'])
sem_name = '/test7'
_handle = create_semaphore(space, sem_name, 1, 1)
w_lock = W_SemLock(space, _handle, 0, 1)
diff --git a/pypy/tool/pytest/test/test_appsupport.py b/pypy/tool/pytest/test/test_appsupport.py
--- a/pypy/tool/pytest/test/test_appsupport.py
+++ b/pypy/tool/pytest/test/test_appsupport.py
@@ -40,22 +40,38 @@
"*AppTestMethod*",
])
-class TestSpaceConfig:
- def test_interp_spaceconfig(self, testdir):
- setpypyconftest(testdir)
- p = testdir.makepyfile("""
- class TestClass:
- spaceconfig = {"objspace.usemodules._random": False}
- def setup_class(cls):
- assert not cls.space.config.objspace.usemodules._random
- def test_interp(self, space):
- assert self.space is space
- def test_interp2(self, space):
- assert self.space is space
- """)
- result = testdir.runpytest(p)
- assert result.ret == 0
- result.stdout.fnmatch_lines(["*2 passed*"])
+def test_interp_spaceconfig(testdir):
+ setpypyconftest(testdir)
+ p = testdir.makepyfile("""
+ class TestClass:
+ spaceconfig = {"objspace.usemodules._random": False}
+ def setup_class(cls):
+ assert not cls.space.config.objspace.usemodules._random
+ def test_interp(self, space):
+ assert self.space is space
+ def test_interp2(self, space):
+ assert self.space is space
+ """)
+ result = testdir.runpytest(p)
+ assert result.ret == 0
+ result.stdout.fnmatch_lines(["*2 passed*"])
+
+def test_spaceconfig_param(testdir):
+ setpypyconftest(testdir)
+ p = testdir.makepyfile("""
+ import pytest
+
+ @pytest.mark.parametrize('spaceconfig',
+ [{"objspace.usemodules._random": False}])
+ def test_interp(space):
+ assert not space.config.objspace.usemodules._random
+
+ def test_interp2(space):
+ assert space.config.objspace.usemodules._random
+ """)
+ result = testdir.runpytest(p)
+ assert result.ret == 0
+ result.stdout.fnmatch_lines(["*2 passed*"])
def test_applevel_raises_simple_display(testdir):
setpypyconftest(testdir)
More information about the pypy-commit
mailing list