summaryrefslogtreecommitdiff
path: root/doc/en/usage.rst
diff options
context:
space:
mode:
authorDave Hunt <dave.hunt@gmail.com>2016-06-21 16:16:57 +0200
committerDave Hunt <dave.hunt@gmail.com>2016-06-21 16:16:57 +0200
commitef9dd1496384cb703bf31a0788ea77bc4184faac (patch)
tree27b6f9583fd61900c88b6d4446a01dd5389834bc /doc/en/usage.rst
parent54872e94b4f3437cb0052a83970133722e79eadd (diff)
downloadpytest-ef9dd1496384cb703bf31a0788ea77bc4184faac.tar.gz
Introduce pytest command as recommended entry point
Fixes #1629
Diffstat (limited to 'doc/en/usage.rst')
-rw-r--r--doc/en/usage.rst66
1 files changed, 33 insertions, 33 deletions
diff --git a/doc/en/usage.rst b/doc/en/usage.rst
index f9add12ab..06cc18969 100644
--- a/doc/en/usage.rst
+++ b/doc/en/usage.rst
@@ -16,7 +16,7 @@ You can invoke testing through the Python interpreter from the command line::
python -m pytest [...]
-This is equivalent to invoking the command line script ``py.test [...]``
+This is equivalent to invoking the command line script ``pytest [...]``
directly.
Getting help on version, option names, environment variables
@@ -24,9 +24,9 @@ Getting help on version, option names, environment variables
::
- py.test --version # shows where pytest was imported from
- py.test --fixtures # show available builtin function arguments
- py.test -h | --help # show help on command line and config file options
+ pytest --version # shows where pytest was imported from
+ pytest --fixtures # show available builtin function arguments
+ pytest -h | --help # show help on command line and config file options
Stopping after the first (or N) failures
@@ -34,45 +34,45 @@ Stopping after the first (or N) failures
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
+ pytest -x # stop after first failure
+ pytest --maxfail=2 # stop after two failures
Specifying tests / selecting tests
---------------------------------------------------
Several test run options::
- py.test test_mod.py # run tests in module
- py.test somepath # run all tests below somepath
- py.test -k stringexpr # only run tests with names that match the
+ pytest test_mod.py # run tests in module
+ pytest somepath # run all tests below somepath
+ pytest -k stringexpr # only run tests with names that match the
# "string expression", e.g. "MyClass and not method"
# will select TestMyClass.test_something
# but not TestMyClass.test_method_simple
- py.test test_mod.py::test_func # only run tests that match the "node ID",
+ pytest test_mod.py::test_func # only run tests that match the "node ID",
# e.g "test_mod.py::test_func" will select
# only test_func in test_mod.py
- py.test test_mod.py::TestClass::test_method # run a single method in
+ pytest test_mod.py::TestClass::test_method # run a single method in
# a single class
Import 'pkg' and use its filesystem location to find and run tests::
- py.test --pyargs pkg # run all tests found below directory of pkg
+ pytest --pyargs pkg # run all tests found below directory of pkg
Modifying Python traceback printing
----------------------------------------------
Examples for modifying traceback printing::
- py.test --showlocals # show local variables in tracebacks
- py.test -l # show local variables (shortcut)
+ pytest --showlocals # show local variables in tracebacks
+ pytest -l # show local variables (shortcut)
- py.test --tb=auto # (default) 'long' tracebacks for the first and last
+ pytest --tb=auto # (default) 'long' tracebacks for the first and last
# entry, but 'short' style for the other entries
- py.test --tb=long # exhaustive, informative traceback formatting
- py.test --tb=short # shorter traceback format
- py.test --tb=line # only one line per failure
- py.test --tb=native # Python standard library formatting
- py.test --tb=no # no traceback at all
+ pytest --tb=long # exhaustive, informative traceback formatting
+ pytest --tb=short # shorter traceback format
+ pytest --tb=line # only one line per failure
+ pytest --tb=native # Python standard library formatting
+ pytest --tb=no # no traceback at all
The ``--full-trace`` causes very long traces to be printed on error (longer
than ``--tb=long``). It also ensures that a stack trace is printed on
@@ -90,14 +90,14 @@ Dropping to PDB_ (Python Debugger) on failures
Python comes with a builtin Python debugger called PDB_. ``pytest``
allows one to drop into the PDB_ prompt via a command line option::
- py.test --pdb
+ pytest --pdb
This will invoke the Python debugger on every failure. Often you might
only want to do this for the first failing test to understand a certain
failure situation::
- py.test -x --pdb # drop to PDB on first failure, then end test session
- py.test --pdb --maxfail=3 # drop to PDB for first three failures
+ pytest -x --pdb # drop to PDB on first failure, then end test session
+ pytest --pdb --maxfail=3 # drop to PDB for first three failures
Note that on any failure the exception information is stored on
``sys.last_value``, ``sys.last_type`` and ``sys.last_traceback``. In
@@ -125,7 +125,7 @@ can use a helper::
.. versionadded: 2.0.0
Prior to pytest version 2.0.0 you could only enter PDB_ tracing if you disabled
-capturing on the command line via ``py.test -s``. In later versions, pytest
+capturing on the command line via ``pytest -s``. In later versions, pytest
automatically disables its output capture when you enter PDB_ tracing:
* Output capture in other tests is not affected.
@@ -141,7 +141,7 @@ automatically disables its output capture when you enter PDB_ tracing:
Since pytest version 2.4.0 you can also use the native Python
``import pdb;pdb.set_trace()`` call to enter PDB_ tracing without having to use
the ``pytest.set_trace()`` wrapper or explicitly disable pytest's output
-capturing via ``py.test -s``.
+capturing via ``pytest -s``.
.. _durations:
@@ -152,7 +152,7 @@ Profiling test execution duration
To get a list of the slowest 10 test durations::
- py.test --durations=10
+ pytest --durations=10
Creating JUnitXML format files
@@ -161,7 +161,7 @@ Creating JUnitXML format files
To create result files which can be read by Jenkins_ or other Continuous
integration servers, use this invocation::
- py.test --junitxml=path
+ pytest --junitxml=path
to create an XML file at ``path``.
@@ -253,7 +253,7 @@ Creating resultlog format files
To create plain-text machine-readable result files you can issue::
- py.test --resultlog=path
+ pytest --resultlog=path
and look at the content at the ``path`` location. Such files are used e.g.
by the `PyPy-test`_ web page to show test results over several revisions.
@@ -266,7 +266,7 @@ Sending test report to online pastebin service
**Creating a URL for each test failure**::
- py.test --pastebin=failed
+ pytest --pastebin=failed
This will submit test run information to a remote Paste service and
provide a URL for each failure. You may select tests as usual or add
@@ -274,7 +274,7 @@ for example ``-x`` if you only want to send one particular failure.
**Creating a URL for a whole test session log**::
- py.test --pastebin=all
+ pytest --pastebin=all
Currently only pasting to the http://bpaste.net service is implemented.
@@ -285,9 +285,9 @@ To disable loading specific plugins at invocation time, use the ``-p`` option
together with the prefix ``no:``.
Example: to disable loading the plugin ``doctest``, which is responsible for
-executing doctest tests from text files, invoke py.test like this::
+executing doctest tests from text files, invoke pytest like this::
- py.test -p no:doctest
+ pytest -p no:doctest
.. _`pytest.main-usage`:
@@ -300,7 +300,7 @@ You can invoke ``pytest`` from Python code directly::
pytest.main()
-this acts as if you would call "py.test" from the command line.
+this acts as if you would call "pytest" from the command line.
It will not raise ``SystemExit`` but return the exitcode instead.
You can pass in options and arguments::