|
| 1 | +.. Jython companion to runtests.rst |
| 2 | +
|
| 3 | +.. _runtests-jy: |
| 4 | + |
| 5 | +Running & Writing Tests (Jython) |
| 6 | +================================ |
| 7 | + |
| 8 | +.. highlight:: console |
| 9 | + |
| 10 | +.. note:: |
| 11 | + |
| 12 | + This document assumes you are working from an |
| 13 | + :ref:`in-development <indevbranch>` checkout of Jython. If you |
| 14 | + are not then some things presented here may not work as they may depend |
| 15 | + on new features not available in earlier versions of Jython. |
| 16 | + |
| 17 | + The commands are given for Jython 2.7, and may be different in Jython 3. |
| 18 | + |
| 19 | +Running |
| 20 | +------- |
| 21 | + |
| 22 | +The shortest, simplest way of running the test suite is the following command |
| 23 | +from the root directory of your checkout:: |
| 24 | + |
| 25 | + $ ant regrtest |
| 26 | + |
| 27 | +This will run the majority of tests, but exclude a small portion of them; |
| 28 | +these excluded tests are known failures on the current platform or |
| 29 | +use special kinds of resources: for example, accessing the |
| 30 | +Internet, or trying to play a sound or to display a graphical interface on |
| 31 | +your desktop. They are disabled by default so that running the test suite |
| 32 | +is not too intrusive. To enable some of these additional tests (and for |
| 33 | +other flags which can help debug various issues such as reference leaks), read |
| 34 | +the help text:: |
| 35 | + |
| 36 | + $ dist/bin/jython -m test.regrtest -h |
| 37 | + |
| 38 | +If you want to run a single test file, simply specify the test file name |
| 39 | +(without the extension) as an argument. You also probably want to enable |
| 40 | +verbose mode (using ``-v``), so that individual failures are detailed:: |
| 41 | + |
| 42 | + $ dist/bin/jython -m test.regrtest -v test_abc |
| 43 | + |
| 44 | +This form may be used to run multiple tests by name, |
| 45 | +and in a the order specified, or even repeat to tests:: |
| 46 | + |
| 47 | + $ dist/bin/jython -m test.regrtest test_abc test_int test_abc |
| 48 | + |
| 49 | +To run a single test case, use the ``unittest`` module, providing the import |
| 50 | +path to the test case:: |
| 51 | + |
| 52 | + $ dist/bin/jython -m unittest -v test.test_abc.TestABC |
| 53 | + |
| 54 | + |
| 55 | +Unexpected Skips |
| 56 | +^^^^^^^^^^^^^^^^ |
| 57 | + |
| 58 | +Sometimes when running the test suite, you will see "unexpected skips" |
| 59 | +reported. These represent cases where an entire test module has been |
| 60 | +skipped, but the test suite normally expects the tests in that module to |
| 61 | +be executed on that platform. |
| 62 | + |
| 63 | +Often, the cause is that an optional module hasn't been built due to missing |
| 64 | +build dependencies. In these cases, the missing module reported when the test |
| 65 | +is skipped should match one of the modules reported as failing to build when |
| 66 | +:ref:`compiling-jy`. |
| 67 | + |
| 68 | +In other cases, the skip message should provide enough detail to help figure |
| 69 | +out and resolve the cause of the problem (for example, the default security |
| 70 | +settings on some platforms will disallow some tests) |
| 71 | + |
| 72 | + |
| 73 | +Writing |
| 74 | +------- |
| 75 | + |
| 76 | +Writing tests for Python is much like writing tests for your own code. Tests |
| 77 | +need to be thorough, fast, isolated, consistently repeatable, and as simple as |
| 78 | +possible. We try to have tests both for normal behaviour and for error |
| 79 | +conditions. Tests live in the ``Lib/test`` directory, where every file that |
| 80 | +includes tests has a ``test_`` prefix. |
| 81 | + |
| 82 | +One difference with ordinary testing is that you are encouraged to rely on the |
| 83 | +:py:mod:`test.support` module. It contains various helpers that are tailored to |
| 84 | +Python's test suite and help smooth out common problems such as platform |
| 85 | +differences, resource consumption and cleanup, or warnings management. |
| 86 | +That module is not suitable for use outside of the standard library. |
| 87 | + |
| 88 | +When you are adding tests to an existing test file, it is also recommended |
| 89 | +that you study the other tests in that file; it will teach you which precautions |
| 90 | +you have to take to make your tests robust and portable. |
| 91 | + |
| 92 | + |
| 93 | +Benchmarks |
| 94 | +---------- |
| 95 | +Benchmarking is useful to test that a change does not degrade performance. |
| 96 | + |
| 97 | +`The Python Benchmark Suite <https://github.com/python/performance>`_ |
| 98 | +has a collection of benchmarks for all Python implementations. Documentation |
| 99 | +about running the benchmarks is in the `README.txt |
| 100 | +<https://github.com/python/performance/blob/master/README.rst>`_ of the repo. |
0 commit comments