• Home
  • Raw
  • Download

Lines Matching +full:runner +full:- +full:before +full:- +full:script

1 :mod:`unittest` --- Unit testing framework
14 --------------
17 to skip to :ref:`the list of assert methods <assert-methods>`.)
26 object-oriented way:
43 test runner
44 A :dfn:`test runner` is a component which orchestrates the execution of tests
45 and provides the outcome to the user. The runner may use a graphical interface,
53 Another test-support module with a very different flavor.
60 Third-party unittest framework with a lighter-weight syntax for writing
67 `Testing in Python Mailing List <http://lists.idyll.org/listinfo/testing-in-python>`_
68 A special-interest-group for discussion of testing, and testing tools,
71 The script :file:`Tools/unittestgui/unittestgui.py` in the Python source distribution is
80 .. _unittest-minimal-example:
83 -------------
89 Here is a short script to test three string methods::
115 ``test``. This naming convention informs the test runner about which methods
122 :keyword:`assert` statement so the test runner can accumulate all test results
126 to define instructions that will be executed before and after each test method.
127 They are covered in more detail in the section :ref:`organizing-tests`.
130 provides a command-line interface to the test script. When run from the command
131 line, the above script produces an output that looks like this::
134 ----------------------------------------------------------------------
139 Passing the ``-v`` option to your test script will instruct :func:`unittest.main`
146 ----------------------------------------------------------------------
160 .. _unittest-command-line-interface:
162 Command-Line Interface
163 ----------------------
168 python -m unittest test_module1 test_module2
169 python -m unittest test_module.TestClass
170 python -m unittest test_module.TestClass.test_method
177 python -m unittest tests/test_something.py
185 You can run tests with more detail (higher verbosity) by passing in the -v flag::
187 python -m unittest -v test_module
189 When executed without arguments :ref:`unittest-test-discovery` is started::
191 python -m unittest
193 For a list of all the command-line options::
195 python -m unittest -h
202 Command-line options
205 :program:`unittest` supports these command-line options:
209 .. cmdoption:: -b, --buffer
215 .. cmdoption:: -c, --catch
217 :kbd:`Control-C` during the test run waits for the current test to end and then
218 reports all the results so far. A second :kbd:`Control-C` raises the normal
223 .. cmdoption:: -f, --failfast
227 .. cmdoption:: -k
234 test name using :meth:`fnmatch.fnmatchcase`; otherwise simple case-sensitive
240 For example, ``-k foo`` matches ``foo_tests.SomeTest.test_something``,
243 .. cmdoption:: --locals
248 The command-line options ``-b``, ``-c`` and ``-f`` were added.
251 The command-line option ``--locals``.
254 The command-line option ``-k``.
260 .. _unittest-test-discovery:
263 --------------
268 discovery, all of the test files must be :ref:`modules <tut-modules>` or
269 :ref:`packages <tut-packages>` importable from the top-level directory of
274 used from the command line. The basic command-line usage is::
277 python -m unittest discover
281 As a shortcut, ``python -m unittest`` is the equivalent of
282 ``python -m unittest discover``. If you want to pass arguments to test
283 discovery the ``discover`` sub-command must be used explicitly.
285 The ``discover`` sub-command has the following options:
289 .. cmdoption:: -v, --verbose
293 .. cmdoption:: -s, --start-directory directory
297 .. cmdoption:: -p, --pattern pattern
301 .. cmdoption:: -t, --top-level-directory directory
305 The :option:`-s`, :option:`-p`, and :option:`-t` options can be passed in
309 python -m unittest discover -s project_directory -p "*_test.py"
310 python -m unittest discover project_directory "*_test.py"
340 ``python -m unittest discover -s root/namespace -t root``).
352 # proj/ <-- current directory
358 python -m unittest discover -s namespace.mypkg -t .
361 .. _organizing-tests:
364 --------------------
366 The basic building blocks of unit testing are :dfn:`test cases` --- single
393 Tests can be numerous, and their set-up can be repetitive. Luckily, we
394 can factor out set-up code by implementing a method called
415 by sorting the test method names with respect to the built-in
460 runner = unittest.TextTestRunner()
461 runner.run(suite())
485 .. _legacy-unit-tests:
487 Re-using old test code
488 ----------------------
496 function. Set-up and tear-down functions can also be provided.
506 set-up and tear-down methods::
515 existing test base over to a :mod:`unittest`\ -based system, this approach is
522 :mod:`doctest`\ -based tests.
525 .. _unittest-skipping:
528 ------------------------------------
573 ----------------------------------------------------------------------
641 ---------------------------------------------
666 ----------------------------------------------------------------------
676 ----------------------------------------------------------------------
686 ----------------------------------------------------------------------
699 ----------------------------------------------------------------------
706 .. _unittest-contents:
709 ---------------------
714 .. _testcase-objects:
724 implements the interface needed by the test runner to allow it to drive the
748 before calling the test method; other than :exc:`AssertionError` or :exc:`SkipTest`,
768 A class method called before tests in an individual class are run.
814 test. See :ref:`unittest-skipping` for more information.
840 .. _assert-methods:
846 +-----------------------------------------+-----------------------------+---------------+
851 +-----------------------------------------+-----------------------------+---------------+
854 +-----------------------------------------+-----------------------------+---------------+
857 +-----------------------------------------+-----------------------------+---------------+
860 +-----------------------------------------+-----------------------------+---------------+
863 +-----------------------------------------+-----------------------------+---------------+
866 +-----------------------------------------+-----------------------------+---------------+
869 +-----------------------------------------+-----------------------------+---------------+
872 +-----------------------------------------+-----------------------------+---------------+
875 +-----------------------------------------+-----------------------------+---------------+
878 +-----------------------------------------+-----------------------------+---------------+
881 +-----------------------------------------+-----------------------------+---------------+
884 +-----------------------------------------+-----------------------------+---------------+
899 registers with :meth:`addTypeEqualityFunc` the type-specific equality
901 error message (see also the :ref:`list of type-specific methods
902 <type-specific-methods>`).
905 Added the automatic calling of type-specific equality function.
967 …+---------------------------------------------------------+--------------------------------------+
972 …+---------------------------------------------------------+--------------------------------------+
975 …+---------------------------------------------------------+--------------------------------------+
978 …+---------------------------------------------------------+--------------------------------------+
981 …+---------------------------------------------------------+--------------------------------------+
984 …+---------------------------------------------------------+--------------------------------------+
987 …+---------------------------------------------------------+--------------------------------------+
1127 non-propagating descendent logger.
1181 +---------------------------------------+--------------------------------+--------------+
1184 | :meth:`assertAlmostEqual(a, b) | ``round(a-b, 7) == 0`` | |
1186 +---------------------------------------+--------------------------------+--------------+
1187 | :meth:`assertNotAlmostEqual(a, b) | ``round(a-b, 7) != 0`` | |
1189 +---------------------------------------+--------------------------------+--------------+
1192 +---------------------------------------+--------------------------------+--------------+
1195 +---------------------------------------+--------------------------------+--------------+
1198 +---------------------------------------+--------------------------------+--------------+
1201 +---------------------------------------+--------------------------------+--------------+
1204 +---------------------------------------+--------------------------------+--------------+
1207 +---------------------------------------+--------------------------------+--------------+
1211 +---------------------------------------+--------------------------------+--------------+
1284 .. _type-specific-methods:
1287 the same type to different type-specific methods. These methods are already
1288 implemented for most of the built-in types, but it's also possible to
1293 Registers a type-specific method called by :meth:`assertEqual` to check
1298 between the first two parameters is detected -- possibly providing useful
1304 The list of type-specific methods automatically used by
1308 +-----------------------------------------+-----------------------------+--------------+
1313 +-----------------------------------------+-----------------------------+--------------+
1316 +-----------------------------------------+-----------------------------+--------------+
1319 +-----------------------------------------+-----------------------------+--------------+
1322 +-----------------------------------------+-----------------------------+--------------+
1325 +-----------------------------------------+-----------------------------+--------------+
1328 +-----------------------------------------+-----------------------------+--------------+
1391 .. _other-methods-and-attrs:
1420 an instance attribute, self.longMessage, to ``True`` or ``False`` before
1423 The class setting gets reset before each test call.
1488 order they are added (:abbr:`LIFO (last-in, first-out)`). They
1528 order to the order they are added (:abbr:`LIFO (last-in, first-out)`).
1574 This is called immediately before calling the test method; other than
1582 result recorded. This is called before :meth:`tearDown`. This is called even if
1657 allows the test runner to drive the test, but does not provide the methods
1660 :mod:`unittest`-based test framework.
1663 .. _deprecated-aliases:
1697 .. _testsuite-objects:
1705 The class presents the interface needed by the test runner to allow it to be run
1753 individual tests and sub-suites.
1762 returned by repeated iterations before :meth:`TestSuite.run` must be the
1779 is invoked by a :class:`TestRunner` rather than by the end-user test harness.
1798 A list of the non-fatal errors encountered while loading tests. Not reset
1800 method raising an exception to the caller. Non-fatal errors are also
1812 Return a suite of all test cases contained in the :class:`TestCase`\ -derived
1831 While using a hierarchy of :class:`TestCase`\ -derived classes can be
1848 compatibility. The method also now accepts a keyword-only argument
1865 :class:`TestCase`\ -derived class :class:`SampleTestCase` with three test
1872 be imported as a side-effect.
1942 Paths are sorted before being imported so that execution order is the
1985 List of Unix shell-style wildcard test name patterns that test methods
1986 have to match to be included in test suites (see ``-k`` option).
1991 so unlike patterns passed to the ``-k`` option, simple substring patterns
2020 A list containing 2-tuples of :class:`TestCase` instances and strings
2026 A list containing 2-tuples of :class:`TestCase` instances and strings
2032 A list containing 2-tuples of :class:`TestCase` instances and strings
2039 A list containing 2-tuples of :class:`TestCase` instances and strings
2116 Called once before any tests are executed.
2220 A basic test runner implementation that outputs results to a stream. If *stream*
2227 By default this runner shows :exc:`DeprecationWarning`,
2230 <warning-ignored>`. Deprecation warnings caused by :ref:`deprecated unittest
2231 methods <deprecated-aliases>` are also special-cased and, when the warning
2233 per-module, in order to avoid too many warning messages. This behavior can
2234 be overridden using Python's :option:`!-Wd` or :option:`!-Wa` options
2235 (see :ref:`Warning control <using-on-warnings>`) and leaving
2274 A command-line program that loads a set of tests from *module* and runs them;
2277 end of a test script::
2297 The *testRunner* argument can either be a test runner class or an already
2312 effect as the same-name `command-line options`_.
2314 The *warnings* argument specifies the :ref:`warning filter <warning-filter>`
2316 remain ``None`` if a :option:`!-W` option is passed to :program:`python`
2317 (see :ref:`Warning control <using-on-warnings>`),
2402 -------------------------
2426 Shared fixtures are not intended to work with suites with non-standard
2434 the standard unittest test runner then this detail doesn't matter, but if you
2489 order to the order they are added (:abbr:`LIFO (last-in, first-out)`).
2526 ---------------
2530 The :option:`-c/--catch <unittest -c>` command-line option to unittest,
2532 more friendly handling of control-C during a test run. With catch break
2533 behavior enabled control-C will allow the currently running test to complete,
2535 control-c will raise a :exc:`KeyboardInterrupt` in the usual way.
2537 The control-c handling signal handler attempts to remain compatible with code or
2543 that need ``unittest`` control-c handling disabled the :func:`removeHandler`
2546 There are a few utility functions for framework authors to enable control-c
2551 Install the control-c handler. When a :const:`signal.SIGINT` is received
2552 (usually in response to the user pressing control-c) all registered results
2558 Register a :class:`TestResult` object for control-c handling. Registering a
2562 Registering a :class:`TestResult` object has no side-effects if control-c
2571 response to a control-c.
2576 When called without arguments this function removes the control-c handler