Skip to main content

easily run python unit tests

Project description

Easy python testing for Python’s unittest module. Pyt’s goal is to make running Python unit tests fun and easy.

pyt testrunner

So here was my problem, I would work on big Python projects, and I would be adding a new python file to a module in this big project:


I would be adding the Happy class with a sad method to newmodule and I would want to test it, so I would then have to add a test for it:


Then to actually run my new test:

$ python -m unittest

This annoyed me! I could never remember the syntax to run the test, I could never remember what I named the test case (let’s see, was that HappyTestCase or HappyTest?), so I decided to take a bit of time and make my life easier, and pyt was born.

With pyt, I just need to remember what I’m working on:

$ pyt Happy.sad

and pyt will do the rest, it will check every test module it finds in the working directory and see if it has a Happy test case with a test_sad method. No more having to remember the unittest syntax, and no more typing long test paths. Hopefully, if tests are easy to run, I’ll write more of them.

More examples

Continuing the above example

To run all the Happy tests:

$ pyt Happy

To run all the newmodule tests:

$ pyt newmodule

To run more than one test:

$ pyt test1 test2 ...

To run every test pyt can find:

$ pyt

And the way I like to run all tests:

$ pyt -bd

Things to be aware of

pyt uses Python’s PEP 8 style conventions

pyt uses Python’s code styling conventions to decide what is the module and class, so, given input like this:

$ pyt

pyt will consider to be the module, Baz to be a class (because it starts with a capital letter), and che to be a method (since it comes after the class).

Likewise, pyt uses unittest conventions, so a test module should end with _test (eg, foo.bar_test) and a TestCase class should end with either Test or TestCase (eg, BazTest), and test methods should start with test_ (eg, test_che).

See all flags

To see everything pyt can do

$ pyt --help

Vague input can cause pyt to run more tests than you expect

So if you have something like this:


And you want to run tests for foo.user and you run:

$ pyt user

it will run both tests/user_test and, the solution is to just be more verbose when you have to be:

$ pyt foo.user

Environment Variables

If you are running the tests within pyt, you might notice there is an environment variable PYT_TEST_COUNT that contains the count of how many tests pyt found to run.


Use pip:

$ pip install pyt

You can also get it directly from the repo:

$ pip install git+

If you install pyt using Python 3 it is called on the command line uses the pyt3 command instead of a pyt command, so:

$ pyt3 --help

While Python 2 installs both pyt and pyt2 commands:

$ pyt2 --help
$ pyt --help


Testing in 2.7 on most systems:

$ python -m unittest pyt_test

Testing in 3.5 on MacOS:

$ python3.5 -m unittest pyt_test

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyt-0.7.31.tar.gz (10.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page