From 8ba2a98e114f1a856d2777c52adc65899c69f2b2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 11 May 2010 19:56:22 +0200 Subject: [PATCH] allow to run py.test.cmdline.main() multiple times. --HG-- branch : trunk --- CHANGELOG | 9 ++++++++- contrib/runtesthelper.py | 5 ++++- py/__init__.py | 1 - py/_cmdline/pytest.py | 4 ++-- py/_test/cmdline.py | 5 +++-- testing/acceptance_test.py | 16 ++++++++++++++++ 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7d59becae..34dc8c4a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,14 @@ Changes between 1.3.0 and 1.3.1 ================================================== -- improve tracebacks showing: +- make py.test.cmdline.main() return the exitstatus + instead of raising (which is still done by py.cmdline.pytest()) + and make it so that py.test.cmdline.main() can be called + multiple times, at least as far as py.test's internal + state is concerned - previously it would raise an exception + on the second time. + +- improve tracebacks presentation: - raises shows shorter more relevant tracebacks Changes between 1.2.1 and 1.3.0 diff --git a/contrib/runtesthelper.py b/contrib/runtesthelper.py index 96c90eb8d..e1c769e0c 100644 --- a/contrib/runtesthelper.py +++ b/contrib/runtesthelper.py @@ -1,7 +1,10 @@ """ this little helper allows to run tests multiple times in the same process. useful for running tests from -a console. +a console. + +NOTE: since 1.3.1 you can just call py.test.cmdline.main() +multiple times - no special logic needed. """ import py, sys diff --git a/py/__init__.py b/py/__init__.py index 36cc5b00d..360bbea27 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -25,7 +25,6 @@ py.apipkg.initpkg(__name__, dict( 'pytest': '._cmdline.pytest:main', 'pylookup': '._cmdline.pylookup:main', 'pycountloc': '._cmdline.pycountlog:main', - 'pytest': '._test.cmdline:main', 'pylookup': '._cmdline.pylookup:main', 'pycountloc': '._cmdline.pycountloc:main', 'pycleanup': '._cmdline.pycleanup:main', diff --git a/py/_cmdline/pytest.py b/py/_cmdline/pytest.py index fc460593c..14e2bc81c 100755 --- a/py/_cmdline/pytest.py +++ b/py/_cmdline/pytest.py @@ -1,5 +1,5 @@ #!/usr/bin/env python import py -def main(args): - py.test.cmdline.main(args) +def main(args=None): + raise SystemExit(py.test.cmdline.main(args)) diff --git a/py/_test/cmdline.py b/py/_test/cmdline.py index 804c42fc1..80ca99d4f 100644 --- a/py/_test/cmdline.py +++ b/py/_test/cmdline.py @@ -16,8 +16,9 @@ def main(args=None): colitems = config.getinitialnodes() exitstatus = session.main(colitems) config.pluginmanager.do_unconfigure(config) - raise SystemExit(exitstatus) except config.Error: e = sys.exc_info()[1] sys.stderr.write("ERROR: %s\n" %(e.args[0],)) - raise SystemExit(3) + exitstatus = 3 + py.test.config = py.test.config.__class__() + return exitstatus diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 78f2ddc65..f3222aa4f 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -89,3 +89,19 @@ class TestGeneralUsage: assert result.ret == 0 s = result.stdout.str() assert 'MarkGenerator' in s + + def test_double_pytestcmdline(self, testdir): + p = testdir.makepyfile(run=""" + import py + py.test.cmdline.main() + py.test.cmdline.main() + """) + testdir.makepyfile(""" + def test_hello(): + pass + """) + result = testdir.runpython(p) + result.stdout.fnmatch_lines([ + "*1 passed*", + "*1 passed*", + ])