allow to run py.test.cmdline.main() multiple times.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-05-11 19:56:22 +02:00
parent 0f5ed3abc7
commit 8ba2a98e11
6 changed files with 33 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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))

View File

@ -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

View File

@ -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*",
])