GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing devguide.python.org — Running and writing tests Running and writing tests¶Note This document assumes you are working from an in-development checkout of Python. If you are not then some things presented here may not work as they may depend on new features not available in earlier versions of Python. Running¶The shortest, simplest way of running the test suite is the following command, which runs tests in parallel, from the root directory of your checkout (after you have built Python):
Unix
./python -m test -j0 ./python.exe -m test -j0 This works on most macOS systems. .\python.bat -m test -j0 This will run the majority of tests, but exclude a small portion of them; these excluded tests use special kinds of resources: for example, accessing the Internet, or trying to play a sound or to display a graphical interface on your desktop. They are disabled by default so that running the test suite is not too intrusive. To enable some of these additional tests (and for other flags which can help debug various issues such as reference leaks), read the help text:
Unix
./python -m test -h ./python.exe -m test -h .\python.bat -m test -h If you want to run a single test file, simply specify the test file name
(without the extension) as an argument. You also probably want to enable
verbose mode (using
Unix
./python -m test -v test_abc ./python.exe -m test -v test_abc .\python.bat -m test -v test_abc To run a single test case, use the
Unix
./python -m unittest -v test.test_abc.TestABC_Py ./python.exe -m unittest -v test.test_abc.TestABC_Py .\python.bat -m unittest -v test.test_abc.TestABC_Py Some test modules also support direct invocation, which might be useful for IDEs and local debugging:
Unix
./python Lib/test/test_typing.py
./python.exe Lib/test/test_typing.py
.\python.bat Lib/test/test_typing.py But, there are several important notes:
By default,
Unix
./python -m test ./python.exe -m test .\python.bat -m test To limit how many tests run at once, pass an explicit number of
worker processes instead, such as Finally, if you want to run tests under a more strenuous set of settings, you
can run
Unix
./python -bb -E -Wd -m test -r -w -uall ./python.exe -bb -E -Wd -m test -r -w -uall .\python.bat -bb -E -Wd -m test -r -w -uall The various extra flags passed to Python cause it to be much stricter about
various things (the To check for reference leaks (only needed if you modified C code),
you can enable reference leak checking during testing using the python -m test <test_name> -R : This default setting performs a few initial warm-up runs to stabilize the reference count, followed by additional runs to check for leaks. If you want more control over the number of runs, you can specify python -m test <test_name> -R <warmups>:<repeats> For instance, You can also execute the Locale support¶Some tests require specific locales to run successfully. These locales are often non-default, non-English, non-UTF-8 locales. If a necessary locale is unavailable, the test is skipped or runs in the dry-run mode. Additional locales that you may find helpful to set up on developer’s machines or buildbots include:
On Linux and macOS, the Unexpected skips¶Sometimes when running the test suite, you will see “unexpected skips” reported. These represent cases where an entire test module has been skipped, but the test suite normally expects the tests in that module to be executed on that platform. Often, the cause is that an optional module hasn’t been built due to missing build dependencies. In these cases, the missing module reported when the test is skipped should match one of the modules reported as failing to build when Compile and build. In other cases, the skip message should provide enough detail to help figure out and resolve the cause of the problem (for example, the default security settings on some platforms will disallow some tests) Writing¶Writing tests for Python is much like writing tests for your own code. Tests
need to be thorough, fast, isolated, consistently repeatable, and as simple as
possible. We try to have tests both for normal behaviour and for error
conditions. Tests live in the One difference with ordinary testing is that you are encouraged to rely on the
When you are adding tests to an existing test file, it is also recommended that you study the other tests in that file; it will teach you which precautions you have to take to make your tests robust and portable. For tests of the C API, see Tests sections in Changing Python’s C API. Benchmarks¶Benchmarking is useful to test that a change does not degrade performance. The Python Benchmark Suite has a collection of benchmarks for all Python implementations. Documentation about running the benchmarks is in the README.txt of the repo. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |