document "setup.py test" to use genscript'ed version.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-10-28 09:29:56 +02:00
parent c9e629c870
commit 2d8bcbdf55
3 changed files with 50 additions and 7 deletions

View File

@ -1,4 +1,5 @@
.. highlightlang:: python
.. _`good practises`:
Good Practises
@ -28,8 +29,7 @@ py.test supports common test layouts.
XXX
.. _`genscript method`:
Generating a py.test standalone Script
-------------------------------------------
@ -38,12 +38,12 @@ If you are a maintainer or application developer and want users
to run tests you can use a facility to generate a standalone
"py.test" script that you can tell users to run::
py.test --genscript=mytest
py.test --genscript=runtests.py
will generate a ``mytest`` script that is, in fact, a ``py.test`` under
disguise. You can tell people to download and then e.g. run it like this::
python mytest --pastebin=all
python runtests.py --pastebin=all
and ask them to send you the resulting URL. The resulting script has
all core features and runs unchanged under Python2 and Python3 interpreters.
@ -51,4 +51,46 @@ all core features and runs unchanged under Python2 and Python3 interpreters.
.. _`Distribute for installation`: http://pypi.python.org/pypi/distribute#installation-instructions
.. _`distribute installation`: http://pypi.python.org/pypi/distribute
Integrating with distutils / ``python setup.py test``
--------------------------------------------------------
You can easily integrate test runs into your distutils or
setuptools based project. Use the `genscript method`_
to generate a standalone py.test script::
py.test --genscript=runtests.py
and make this script part of your distribution and then add
this to your ``setup.py`` file::
from distutils.core import setup, Command
# you can also import from setuptools
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys,subprocess
errno = subprocess.call([sys.executable, 'runtest.py'])
raise SystemExit(errno)
setup(
#...,
cmdclass = {'test': PyTest},
#...,
)
If you now type::
python setup.py test
this will execute your tests using ``runtest.py``. As this is a
standalone version of ``py.test`` no prior installation whatsoever is
required for calling the test command. You can also pass additional
arguments to the subprocess-calls like your test directory or other
options.
.. include:: links.inc

View File

@ -58,7 +58,7 @@ def pytest_cmdline_main(config):
genscript = config.getvalue("genscript")
if genscript:
script = generate_script(
'import py; py.test.cmdline.main()',
'import py; raise SystemExit(py.test.cmdline.main())',
['py', 'pytest'],
)

View File

@ -19,13 +19,14 @@ class Standalone:
return testdir._run(anypython, self.script, *args)
def test_gen(testdir, anypython, standalone):
result = standalone.run(anypython, testdir, '-h')
assert result.ret == 0
result = standalone.run(anypython, testdir, '--version')
assert result.ret == 0
result.stderr.fnmatch_lines([
"*imported from*mypytest"
])
p = testdir.makepyfile("def test_func(): assert 0")
result = standalone.run(anypython, testdir, p)
assert result.ret != 0
@py.test.mark.xfail(reason="fix-dist", run=False)
def test_rundist(testdir, pytestconfig, standalone):