implement and document new invocation mechanisms, see doc/usage.txt

also rename pytest._core to pytest.main for convenience.
This commit is contained in:
holger krekel
2010-11-05 23:37:31 +01:00
parent 6a734efe44
commit d108235095
22 changed files with 228 additions and 106 deletions
+1
View File
@@ -4,6 +4,7 @@
py.test reference documentation
================================================
.. toctree::
:maxdepth: 2
+13 -15
View File
@@ -1,7 +1,19 @@
pytest builtin helpers
py.test builtin helpers
================================================
builtin py.test.* helpers
-----------------------------------------------------
You can always use an interactive Python prompt and type::
import pytest
help(pytest)
to get an overview on available globally available helpers.
.. automodule:: pytest
:members:
builtin function arguments
-----------------------------------------------------
@@ -54,17 +66,3 @@ You can ask for available builtin or project-custom
* ``pop(category=None)``: return last warning matching the category.
* ``clear()``: clear list of warnings
builtin py.test.* helpers
-----------------------------------------------------
You can always use an interactive Python prompt and type::
import pytest
help(pytest)
to get an overview on available globally available helpers.
.. automodule:: pytest
:members:
+3 -3
View File
@@ -58,8 +58,8 @@ builtin configuration file options
.. confval:: norecursedirs
Set the directory basename patterns to avoid when recursing
for test discovery. The individual (fnmatch-style) patterns are
applied to the basename of a directory to decide if to recurse into it.
for test discovery. The individual (fnmatch-style) patterns are
applied to the basename of a directory to decide if to recurse into it.
Pattern matching characters::
* matches everything
@@ -68,7 +68,7 @@ builtin configuration file options
[!seq] matches any char not in seq
Default patterns are ``.* _* CVS {args}``. Setting a ``norecurse``
replaces the default. Here is a customizing example for avoiding
replaces the default. Here is a customizing example for avoiding
a different set of directories::
# content of setup.cfg
+3 -3
View File
@@ -5,8 +5,8 @@ no-boilerplate testing with Python
----------------------------------
- automatic, fully customizable Python test discovery
- :pep:`8` consistent testing style
- allows simple test functions
- allows fully :pep:`8` compliant coding style
- write simple test functions and freely group tests
- ``assert`` statement for your assertions
- powerful parametrization of test functions
- rely on powerful traceback and assertion reporting
@@ -25,8 +25,8 @@ extensive plugin and customization system
mature command line testing tool
--------------------------------------
- powerful :ref:`usage` possibilities
- used in many projects, ranging from 10 to 10K tests
- autodiscovery of tests
- simple well sorted command line options
- runs on Unix, Windows from Python 2.4 up to Python 3.1 and 3.2
- is itself tested extensively on a CI server
+11 -6
View File
@@ -76,16 +76,21 @@ You can always run your tests by pointing to it::
...
.. _`package name`:
.. note::
.. note::
Test modules are imported under their fully qualified name as follows:
* ``basedir`` = first upward directory not containing an ``__init__.py``
* find ``basedir`` -- this is the first "upward" directory not
containing an ``__init__.py``
* perform ``sys.path.insert(0, basedir)``.
* perform ``sys.path.insert(0, basedir)`` to make the fully
qualified test module path importable.
* ``import path.to.test_module``
* ``import path.to.test_module`` where the path is determined
by converting path separators into "." files. This means
you must follow the convention of having directory and file
names map to the import names.
.. _standalone:
.. _`genscript method`:
@@ -94,7 +99,7 @@ Generating a py.test standalone Script
-------------------------------------------
If you are a maintainer or application developer and want others
to easily run tests you can generate a completely standalone "py.test"
to easily run tests you can generate a completely standalone "py.test"
script::
py.test --genscript=runtests.py
+6 -3
View File
@@ -3,10 +3,14 @@ py.test: no-boilerplate testing with Python
.. todolist::
.. note::
version 2.0 introduces ``pytest`` as the main Python import name
but for historic reasons ``py.test`` remains fully valid and
represents the same package.
Welcome to ``py.test`` documentation:
.. toctree::
.. toctree::
:maxdepth: 2
overview
@@ -27,4 +31,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
+1 -1
View File
@@ -7,7 +7,7 @@ Overview and Introduction
features.txt
getting-started.txt
cmdline.txt
usage.txt
goodpractises.txt
faq.txt
+1 -1
View File
@@ -35,7 +35,7 @@ However easy_install does not provide an uninstall facility.
.. IMPORTANT::
Ensure that you manually delete the init_cov_core.pth file in your site-packages directory.
Ensure that you manually delete the init_covmain.pth file in your site-packages directory.
This file starts coverage collection of subprocesses if appropriate during site initialisation
at python startup.
+58 -4
View File
@@ -1,9 +1,12 @@
.. _usage:
Usage and Invocations
==========================================
.. _cmdline:
Using the interactive command line
===============================================
Getting help on version, option names, environment vars
-----------------------------------------------------------
@@ -22,6 +25,57 @@ To stop the testing process after the first (N) failures::
py.test -x # stop after first failure
py.test -maxfail=2 # stop after two failures
calling pytest from Python code
----------------------------------------------------
.. versionadded: 2.0
You can invoke ``py.test`` from Python code directly::
pytest.main()
this acts as if you would call "py.test" from the command line.
It will not raise ``SystemExit`` but return the exitcode instead.
You can pass in options and arguments::
pytest.main(['x', 'mytestdir'])
or pass in a string::
pytest.main("-x mytestdir")
You can specify additional plugins to ``pytest.main``::
# content of myinvoke.py
import pytest
class MyPlugin:
def pytest_addoption(self, parser):
raise pytest.UsageError("hi from our plugin")
pytest.main(plugins=[MyPlugin()])
Running it will exit quickly::
$ python myinvoke.py
ERROR: hi from our plugin
calling pytest through ``python -m pytest``
-----------------------------------------------------
.. versionadded: 2.0
You can invoke testing through the Python interpreter from the command line::
python -m pytest.main [...]
Python2.7 and Python3 introduced specifying packages to "-m" so there
you can also type::
python -m pytest [...]
All of these invocations are equivalent to the ``py.test [...]`` command line invocation.
Modifying Python traceback printing
----------------------------------------------
@@ -40,7 +94,7 @@ Dropping to PDB (Python Debugger) on failures
.. _PDB: http://docs.python.org/library/pdb.html
Python comes with a builtin Python debugger called PDB_. ``py.test``
Python comes with a builtin Python debugger called PDB_. ``py.test``
allows to drop into the PDB prompt via a command line option::
py.test --pdb