How does it work?

pytddmon essentially does only two things:

  1. Monitors file changes
  2. Runs unit tests
File monitoring
When you run pytddmon in your projects’ source code directory, it repeatedly (0.5 times per second per default) checks whether any *.py file has changed. It looks both in the current directory, and in all sub directories.

When pytddmon detects that something has changed, for example that a unit test or code file has been created or its modify time stamp is different from previously, it runs all tests it can find.

Unit test running
By default, pytddmon determines what files are unit test files by the following criteria:
  • The file name should match the pattern test_*.py
  • It should be located in a directory that is a package
For example, test_something.py located in tests\ would be run if ’tests’ is a package (that is, if there is an __init__.py script in the tests directory, see Python Packages).

Accepted unit tests
pytddmon assumes you write your unit tests with the built-in package unittest.

The simplest possible unit test + code file would look something like this:

# File code.py
def fn():
    return 1

# File test_code.py
import unittest
import code

class CodeTests(unittest.TestCase):
    def test_fn_returns_one(self):
        assert code.fn() == 1

Sharing Buttons by Linksku