2009-03-22 08:38:43 +08:00
|
|
|
.. _`setuptools installation`: http://pypi.python.org/pypi/setuptools
|
|
|
|
|
|
|
|
|
2009-04-02 15:10:16 +08:00
|
|
|
==================
|
|
|
|
Quickstart
|
|
|
|
==================
|
2009-03-22 08:38:43 +08:00
|
|
|
|
|
|
|
This document assumes basic python knowledge. If you have a
|
|
|
|
`setuptools installation`_, install ``py.test`` by typing::
|
|
|
|
|
|
|
|
easy_install -U py
|
|
|
|
|
|
|
|
For alternative installation methods please see the download_ page.
|
|
|
|
|
|
|
|
You should now have a ``py.test`` command line tool and can
|
|
|
|
look at its documented cmdline options via this command::
|
|
|
|
|
|
|
|
py.test -h
|
|
|
|
|
|
|
|
Writing and running a test
|
2009-04-02 15:10:16 +08:00
|
|
|
==========================
|
2009-03-22 08:38:43 +08:00
|
|
|
|
|
|
|
``py.test`` is the command line tool to run tests.
|
|
|
|
Let's write a first test module by putting the following
|
|
|
|
test function into a ``test_sample.py`` file::
|
|
|
|
|
|
|
|
# content of test_sample.py
|
|
|
|
def test_answer():
|
|
|
|
assert 42 == 43
|
|
|
|
|
|
|
|
Now you can run the test by passing it as an argument::
|
|
|
|
|
|
|
|
py.test test_sample.py
|
|
|
|
|
|
|
|
What does happen here? ``py.test`` looks for functions and
|
|
|
|
methods in the module that start with ``test_``. It then
|
|
|
|
executes those tests. Assertions about test outcomes are
|
|
|
|
done via the standard ``assert`` statement.
|
|
|
|
|
|
|
|
You can also use ``py.test`` to run all tests in a directory structure by
|
|
|
|
invoking it without any arguments::
|
|
|
|
|
|
|
|
py.test
|
|
|
|
|
|
|
|
This will automatically collect and run any Python module whose filenames
|
|
|
|
start with ``test_`` or ends with ``_test`` from the directory and any
|
|
|
|
subdirectories, starting with the current directory, and run them. Each
|
|
|
|
Python test module is inspected for test methods starting with ``test_``.
|
|
|
|
|
|
|
|
.. Organising your tests
|
|
|
|
.. ---------------------------
|
|
|
|
|
2009-07-04 22:14:14 +08:00
|
|
|
Please refer to `features`_ for a walk through the basic features
|
|
|
|
or checkout the `tutorials`_ page for more introduction material.
|
2009-03-22 08:38:43 +08:00
|
|
|
|
2009-04-13 21:58:26 +08:00
|
|
|
.. _download: ../download.html
|
|
|
|
.. _features: features.html
|
2009-07-04 22:14:14 +08:00
|
|
|
.. _tutorials: talks.html
|
|
|
|
|
2009-03-22 08:38:43 +08:00
|
|
|
|
|
|
|
|