trivially modernize these instructions

[Imported from Trac: page HowToWriteTests, version 12]
exarkun 2020-07-14 15:39:01 +00:00
parent a107de353d
commit 1c56295d4f

@ -7,17 +7,22 @@ touch src/allmydata/test/test_fname.py
```
```
python setup.py trial -s allmydata.test.test_fname
python -m twisted.trial 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:
Okay, so that was boring because there are no tests in the file. Add these contents:
```
from twisted.trial import unittest
from testtools.matchers import (
Never,
)
from .common import (
TestCase,
)
class T(unittest.TestCase):
class T(TestCase):
def test_a(self):
pass
self.assertThat("a", Never())
```
Now run it!
@ -27,18 +32,14 @@ Now run it!
Now install Ned Batchelder's "[coverage"](http://nedbatchelder.com/code/coverage/) tool and run your test with code coverage, like this:
```
python setup.py trial --coverage -s allmydata.test.test_fname
python -m coverage run -m twisted.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:
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.<something>` into the current directory. Run the following command to read that file and produce nice HTML pages:
```
coverage html
```
If you installed coverage from Debian or Ubuntu then you have to name it `python-coverage`, like this:
```
python-coverage html
python -m coverage combine
python -m coverage html
```
That will product a directory named `htmlcov`. View its contents with a web browser.