Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r51763:1b6b08120524
Date: 2012-01-25 17:00 +0100
http://bitbucket.org/pypy/pypy/changeset/1b6b08120524/
Log: skip docstring-tests when running with -A
diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -422,13 +422,11 @@
def runtest(self):
target = self.obj
+ src = extract_docstring_if_empty_function(target)
if self.config.option.runappdirect:
- if self.config.option.appdirect:
- return run_with_python(self.config.option.appdirect, target)
- return target()
+ return run_appdirect_or_skip(self.config, target, src)
space = gettestobjspace()
filename = self._getdynfilename(target)
- src = extract_docstring_if_empty_function(target)
func = app2interp_temp(src, filename=filename)
print "executing", func
self.execute_appex(space, func, space)
@@ -468,17 +466,27 @@
def runtest(self):
target = self.obj
+ src = extract_docstring_if_empty_function(target.im_func)
if self.config.option.runappdirect:
- if self.config.option.appdirect:
- return run_with_python(self.config.option.appdirect, target)
- return target()
+ return run_appdirect_or_skip(self.config, target, src)
space = target.im_self.space
filename = self._getdynfilename(target)
- src = extract_docstring_if_empty_function(target.im_func)
func = app2interp_temp(src, filename=filename)
w_instance = self.parent.w_instance
self.execute_appex(space, func, space, w_instance)
+def run_appdirect_or_skip(config, target, src):
+ if config.option.appdirect:
+ return run_with_python(self.config.option.appdirect, target)
+ if isinstance(src, str):
+ # we are trying to directly run a test whose code is inside
+ # the docstring. This cannot work because the code might
+ # contain py3k-only syntax, while we are on a python2 hosting
+ # python. So, we just skip the test
+ py.test.skip('Cannot run docstring-tests with -A')
+ return target()
+
+
def extract_docstring_if_empty_function(fn):
def empty_func():
""
diff --git a/pypy/tool/pytest/test/test_conftest1.py
b/pypy/tool/pytest/test/test_conftest1.py
--- a/pypy/tool/pytest/test/test_conftest1.py
+++ b/pypy/tool/pytest/test/test_conftest1.py
@@ -59,3 +59,13 @@
assert skipped == []
assert "app_test_code_in_docstring_failing" in failed[0].nodeid
+ def test_docstring_runappdirect(self, testdir):
+ sorter = testdir.inline_run(innertest,
+ '-k', 'test_code_in_docstring',
+ '--runappdirect')
+ passed, skipped, failed = sorter.listoutcomes()
+ assert len(passed) == 1
+ assert len(skipped) == 2
+ assert "test_code_in_docstring_ignored" in passed[0].nodeid
+ assert "app_test_code_in_docstring" in skipped[0].nodeid
+ assert "test_code_in_docstring_failing" in skipped[1].nodeid
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit