mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Move the basic examples section back to the beginning.
This commit is contained in:
parent
b4a81c838a
commit
b09f198362
1 changed files with 67 additions and 63 deletions
|
@ -91,70 +91,7 @@ need to derive from a specific class.
|
||||||
Tools for creating mock test objects (objects simulating external resources).
|
Tools for creating mock test objects (objects simulating external resources).
|
||||||
|
|
||||||
|
|
||||||
.. _unittest-command-line-interface:
|
|
||||||
|
|
||||||
Command Line Interface
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
The unittest module can be used from the command line to run tests from
|
|
||||||
modules, classes or even individual test methods::
|
|
||||||
|
|
||||||
python -m unittest test_module1 test_module2
|
|
||||||
python -m unittest test_module.TestClass
|
|
||||||
python -m unittest test_module.TestClass.test_method
|
|
||||||
|
|
||||||
You can pass in a list with any combination of module names, and fully
|
|
||||||
qualified class or method names.
|
|
||||||
|
|
||||||
You can run tests with more detail (higher verbosity) by passing in the -v flag::
|
|
||||||
|
|
||||||
python-m unittest -v test_module
|
|
||||||
|
|
||||||
For a list of all the command line options::
|
|
||||||
|
|
||||||
python -m unittest -h
|
|
||||||
|
|
||||||
.. versionchanged:: 2.7
|
|
||||||
In earlier versions it was only possible to run individual test methods and
|
|
||||||
not modules or classes.
|
|
||||||
|
|
||||||
The command line can also be used for test discovery, for running all of the
|
|
||||||
tests in a project or just a subset.
|
|
||||||
|
|
||||||
|
|
||||||
.. _unittest-test-discovery:
|
|
||||||
|
|
||||||
Test Discovery
|
|
||||||
--------------
|
|
||||||
|
|
||||||
.. versionadded:: 2.7
|
|
||||||
|
|
||||||
unittest supports simple test discovery. For a project's tests to be
|
|
||||||
compatible with test discovery they must all be importable from the top level
|
|
||||||
directory of the project; i.e. they must all be in Python packages.
|
|
||||||
|
|
||||||
Test discovery is implemented in :meth:`TestLoader.discover`, but can also be
|
|
||||||
used from the command line. The basic command line usage is::
|
|
||||||
|
|
||||||
cd project_directory
|
|
||||||
python -m unittest discover
|
|
||||||
|
|
||||||
The ``discover`` sub-command has the following options:
|
|
||||||
|
|
||||||
-v, --verbose Verbose output
|
|
||||||
-s directory Directory to start discovery ('.' default)
|
|
||||||
-p pattern Pattern to match test files ('test*.py' default)
|
|
||||||
-t directory Top level directory of project (default to
|
|
||||||
start directory)
|
|
||||||
|
|
||||||
The -s, -p, & -t options can be passsed in as positional arguments. The
|
|
||||||
following two command lines are equivalent::
|
|
||||||
|
|
||||||
python -m unittest -s project_directory -p '*_test.py'
|
|
||||||
python -m unittest project_directory '*_test.py'
|
|
||||||
|
|
||||||
Test modules and packages can customize test loading and discovery by through
|
|
||||||
the `load_tests protocol`_.
|
|
||||||
|
|
||||||
.. _unittest-minimal-example:
|
.. _unittest-minimal-example:
|
||||||
|
|
||||||
|
@ -243,6 +180,73 @@ The above examples show the most commonly used :mod:`unittest` features which
|
||||||
are sufficient to meet many everyday testing needs. The remainder of the
|
are sufficient to meet many everyday testing needs. The remainder of the
|
||||||
documentation explores the full feature set from first principles.
|
documentation explores the full feature set from first principles.
|
||||||
|
|
||||||
|
|
||||||
|
.. _unittest-command-line-interface:
|
||||||
|
|
||||||
|
Command Line Interface
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The unittest module can be used from the command line to run tests from
|
||||||
|
modules, classes or even individual test methods::
|
||||||
|
|
||||||
|
python -m unittest test_module1 test_module2
|
||||||
|
python -m unittest test_module.TestClass
|
||||||
|
python -m unittest test_module.TestClass.test_method
|
||||||
|
|
||||||
|
You can pass in a list with any combination of module names, and fully
|
||||||
|
qualified class or method names.
|
||||||
|
|
||||||
|
You can run tests with more detail (higher verbosity) by passing in the -v flag::
|
||||||
|
|
||||||
|
python-m unittest -v test_module
|
||||||
|
|
||||||
|
For a list of all the command line options::
|
||||||
|
|
||||||
|
python -m unittest -h
|
||||||
|
|
||||||
|
.. versionchanged:: 2.7
|
||||||
|
In earlier versions it was only possible to run individual test methods and
|
||||||
|
not modules or classes.
|
||||||
|
|
||||||
|
The command line can also be used for test discovery, for running all of the
|
||||||
|
tests in a project or just a subset.
|
||||||
|
|
||||||
|
|
||||||
|
.. _unittest-test-discovery:
|
||||||
|
|
||||||
|
Test Discovery
|
||||||
|
--------------
|
||||||
|
|
||||||
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
Unittest supports simple test discovery. For a project's tests to be
|
||||||
|
compatible with test discovery they must all be importable from the top level
|
||||||
|
directory of the project (in other words, they must all be in Python packages).
|
||||||
|
|
||||||
|
Test discovery is implemented in :meth:`TestLoader.discover`, but can also be
|
||||||
|
used from the command line. The basic command line usage is::
|
||||||
|
|
||||||
|
cd project_directory
|
||||||
|
python -m unittest discover
|
||||||
|
|
||||||
|
The ``discover`` sub-command has the following options:
|
||||||
|
|
||||||
|
-v, --verbose Verbose output
|
||||||
|
-s directory Directory to start discovery ('.' default)
|
||||||
|
-p pattern Pattern to match test files ('test*.py' default)
|
||||||
|
-t directory Top level directory of project (default to
|
||||||
|
start directory)
|
||||||
|
|
||||||
|
The -s, -p, & -t options can be passsed in as positional arguments. The
|
||||||
|
following two command lines are equivalent::
|
||||||
|
|
||||||
|
python -m unittest -s project_directory -p '*_test.py'
|
||||||
|
python -m unittest project_directory '*_test.py'
|
||||||
|
|
||||||
|
Test modules and packages can customize test loading and discovery by through
|
||||||
|
the `load_tests protocol`_.
|
||||||
|
|
||||||
|
|
||||||
.. _organizing-tests:
|
.. _organizing-tests:
|
||||||
|
|
||||||
Organizing test code
|
Organizing test code
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue