pytest + OS X notifications = happy developers
pytest-osxnotify is a plugin for the pytest testing tool. It adds OS X notifications to your test runs so you know when a test run completes and whether it failed or succeeded without looking at your terminal window.
This is especially useful when you re-run your tests automatically every time a source file was modified.
A quick example
Installing pytest-osxnotify is easy. Let’s set up a simple example that shows you how to use pytest so that it watches your source files for modifications and re-runs the tests as necessary.
We start by installing pytest, pytest-xdist and pytest-osxnotify1.
$ pip install pytest pytest-xdist pytest-osxnotify
Let’s also create a simple test file for us to run. Save the following as
example_test.py in the current folder.
def test_example1(): assert True def test_example2(): assert True def test_example3(): assert True
Now we start the pytest watcher that monitors our source file for modifications and re-runs the tests when necessary.
$ py.test -f example_test.py
That’s it. We can now move our terminal to the background and hack away in our favourite editor knowing that we’ll stay informed about the results of our test runs.