| 1 |
= Testing Readme = |
|---|
| 2 |
|
|---|
| 3 |
So, you want to see what's broken? Eeeexcellent. |
|---|
| 4 |
|
|---|
| 5 |
If you are running python < 2.4.4, please see the troubleshooting section. |
|---|
| 6 |
|
|---|
| 7 |
== Quick Start == |
|---|
| 8 |
First thing to do is run the tests. |
|---|
| 9 |
If you have genshi and twill installed on your system, you should be able to run the tests like this: |
|---|
| 10 |
{{{ |
|---|
| 11 |
PYTHONPATH=. ./trac/test.py |
|---|
| 12 |
}}} |
|---|
| 13 |
|
|---|
| 14 |
== Slow Start == |
|---|
| 15 |
If you want to test against specific versions of genshi, twill, pygments, etc., you can set those up like this: |
|---|
| 16 |
{{{ |
|---|
| 17 |
myworktree/trac |
|---|
| 18 |
/pygments-0.8 |
|---|
| 19 |
/twill-0.9 |
|---|
| 20 |
/genshi-0.4.4 |
|---|
| 21 |
}}} |
|---|
| 22 |
|
|---|
| 23 |
Run `python setup egg_info` in those subdirectories as needed. |
|---|
| 24 |
Then you can run: |
|---|
| 25 |
{{{ |
|---|
| 26 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 ./trac/test.py |
|---|
| 27 |
}}} |
|---|
| 28 |
|
|---|
| 29 |
If you want to run just the functional tests, you can do that by running |
|---|
| 30 |
{{{ |
|---|
| 31 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 ./trac/tests/functional/testcases.py |
|---|
| 32 |
}}} |
|---|
| 33 |
|
|---|
| 34 |
And to run everything except the functional tests, |
|---|
| 35 |
{{{ |
|---|
| 36 |
PYTHONPATH=. ./trac/test.py --skip-functional-tests |
|---|
| 37 |
}}} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
NOTE: Unlike most unittests, the functional tests share a test fixture across tests. This means that you can't(*) run just one of the tests by itself. |
|---|
| 41 |
But you can run a sub-set of the functional tests: |
|---|
| 42 |
{{{ |
|---|
| 43 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 ./trac/tests/functional/__init__.py |
|---|
| 44 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 ./trac/ticket/tests/functional.py |
|---|
| 45 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 ./trac/versioncontrol/tests/functional.py |
|---|
| 46 |
}}} |
|---|
| 47 |
Note that that there is a set of functional tests that are run regardless of what subset you choose; these tests setup the shared fixture. |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
(*) Unless you modify the code to comment out the other functional tests. The test fixture is setup and torn down by `FunctionalTestSuite`, and it runs the tests added to it with `_tester` and `_testenv` set in the testcase objects. |
|---|
| 51 |
|
|---|
| 52 |
The functional tests require subversion, and use a random local port 8000-8999 for the test web server. |
|---|
| 53 |
|
|---|
| 54 |
== Testing output and byproducts == |
|---|
| 55 |
There is some logging done: |
|---|
| 56 |
- testing.log |
|---|
| 57 |
output from trac environment creation, tracd, and some svn commands |
|---|
| 58 |
- functional-testing.log |
|---|
| 59 |
output from twill |
|---|
| 60 |
|
|---|
| 61 |
The test fixture is left behind in 'testenv' so you can inspect it when debugging a problem. |
|---|
| 62 |
{{{ |
|---|
| 63 |
testenv/htpasswd -- the password/authentication for the test fixture. password = username |
|---|
| 64 |
/repo -- the Subversion repository |
|---|
| 65 |
/trac -- the Trac environment |
|---|
| 66 |
}}} |
|---|
| 67 |
(Note that running the tests again will automatically delete this test environment and create a new one. If you want to save a test environment, you will need to rename this directory before running the tests again.) |
|---|
| 68 |
|
|---|
| 69 |
The command to serve the test environment is: |
|---|
| 70 |
{{{ |
|---|
| 71 |
PYTHONPATH=.:../twill-0.9:../genshi-0.4.4:../pygments-0.8 \ |
|---|
| 72 |
./trac/web/standalone.py --basic-auth=trac,testenv/htpasswd, -s \ |
|---|
| 73 |
--port=8888 testenv/trac |
|---|
| 74 |
}}} |
|---|
| 75 |
This is particularly useful when a test fails and you want to explore the environment to debug the problem. |
|---|
| 76 |
|
|---|
| 77 |
== Test Coverage == |
|---|
| 78 |
You can now determine statement coverage of unittests and functional tests. But you'll have to run them separately for now. |
|---|
| 79 |
|
|---|
| 80 |
`figleaf` will need to be on your `PATH`. Set the `FIGLEAF` environment variable to the figleaf command. |
|---|
| 81 |
|
|---|
| 82 |
Create a figleaf-exclude file with filename patterns to exclude. For example: |
|---|
| 83 |
{{{ |
|---|
| 84 |
/usr/lib/python.*/.*.py |
|---|
| 85 |
.*.html |
|---|
| 86 |
}}} |
|---|
| 87 |
|
|---|
| 88 |
Then run the tests something like this: |
|---|
| 89 |
{{{ |
|---|
| 90 |
export FIGLEAF=figleaf |
|---|
| 91 |
figleaf ./trac/test.py -v --skip-functional-tests |
|---|
| 92 |
mv .figleaf .figleaf.unittests |
|---|
| 93 |
python trac/tests/functional/testcases.py -v |
|---|
| 94 |
mv .figleaf .figleaf.functional |
|---|
| 95 |
figleaf2html --exclude-patterns=../figleaf-exclude .figleaf.functional .figleaf.unittests |
|---|
| 96 |
}}} |
|---|
| 97 |
Also, this is very slow; on a decent machine, 10 minutes for the functional tests is normal. |
|---|
| 98 |
|
|---|
| 99 |
To run without figleaf, be sure to unset `FIGLEAF`. |
|---|
| 100 |
|
|---|
| 101 |
-------------------------------------------------------------------------------- |
|---|
| 102 |
== TROUBLESHOOTING: == |
|---|
| 103 |
|
|---|
| 104 |
1. trac-admin is failing on initenv with this exception: |
|---|
| 105 |
{{{ |
|---|
| 106 |
raise Exception('Failed with exitcode %s running trac-admin with %r' % (retval, args)) |
|---|
| 107 |
Exception: Failed with exitcode 1 running trac-admin with ('initenv', 'testenv', 'sqlite:db/trac.db', 'svn', '..../testenv/repo') |
|---|
| 108 |
}}} |
|---|
| 109 |
This can be caused by not having run `python setup.py egg_info` in the genshi tree. |
|---|
| 110 |
|
|---|
| 111 |
2. Windows needs an implementation of crypt or fcrypt. Carey Evans' pure |
|---|
| 112 |
python version works, but prints warnings on Python 2.3 (they can be |
|---|
| 113 |
ignored). See http://carey.geek.nz/code/python-fcrypt/ |
|---|
| 114 |
|
|---|
| 115 |
3. Python versions compatibility notes |
|---|
| 116 |
* If using Python >=2.4.0, <2.4.4, you need to backport `unittest` from |
|---|
| 117 |
2.4.4. If you do not do this, you will get an `AttributeError` regarding |
|---|
| 118 |
`_fixture` being unset on every test. |
|---|
| 119 |
* If using Python >=2.3.0, <2.3.5, you need to backport a few modules for |
|---|
| 120 |
`setuptools` to work properly (`httplib2`, `cookielib`, `_*CookieJar`) and |
|---|
| 121 |
remove the tuple imports to replace with explicit line continuations. |
|---|
| 122 |
* If using Python >=2.3.0, <2.4.0, you need `subprocess`, `unittest`, and |
|---|
| 123 |
`traceback` from 2.4.4. On Windows you also need to modify `subprocess.py` |
|---|
| 124 |
to use `pywin32` instead of `_subprocess`. Twill includes a `subprocess` |
|---|
| 125 |
module that will not work in this situation because it is not modified. |
|---|
| 126 |
|
|---|