more about setting up your first test file
[Imported from Trac: page HowToWriteTests, version 2]
parent
47fd44d40f
commit
618ede1ad9
|
@ -1,3 +1,5 @@
|
|||
# create a test file
|
||||
|
||||
Choose a name for your test file. We'll use `test_fname.py`:
|
||||
|
||||
```
|
||||
|
@ -8,3 +10,32 @@ touch src/allmydata/test/test_fname.py
|
|||
./bin/tahoe debug trial allmydata.test.test_fname
|
||||
```
|
||||
|
||||
Okay, so it didn't work, because there is no file by that name. Create such a file, with these contents:
|
||||
|
||||
```
|
||||
rom twisted.trial import unittest
|
||||
|
||||
class T(unittest.TestCase):
|
||||
def test_a(self):
|
||||
pass
|
||||
```
|
||||
|
||||
Now install Ned Batchelder's "[coverage"](http://nedbatchelder.com/code/coverage/) tool and run your with code coverage, like this:
|
||||
|
||||
```
|
||||
./bin/tahoe @coverage run --branch --include='src/allmydata/*' @tahoe debug trial allmydata.test.test_fname
|
||||
```
|
||||
|
||||
If you installed coverage from Debian or Ubuntu then you have to name it `python-coverage`, like this:
|
||||
|
||||
```
|
||||
./bin/tahoe @python-coverage run --branch --include='src/allmydata/*' @tahoe debug trial allmydata.test.test_fname
|
||||
```
|
||||
|
||||
This does the same as running the tests without coverage -- print a list of what happened when each test was run. It also writes out a file named `.coverage` into the current directory. Run the following command to read that file and produce nice HTML pages:
|
||||
|
||||
```
|
||||
./bin/tahoe @coverage html
|
||||
```
|
||||
|
||||
That will product a directory named `htmlcov`. View its contents with a web browser.
|
Loading…
Reference in a new issue