Skip to main content

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, for example, my new file might be something like this:

/project/foo/bar/che/baz/newmodule.py

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:

/project/test/foo/bar/che/baz/newmodule_test.py

Then I would want to test my new class method:

$ python -m unittest test.foo.bar.che.baz.newmodule_test.HappyTestCase.test_sad

This got really annoying! Everytime, I would have to remember the syntax to call unittest from the command line, and then I would have to 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 simplify it, that’s when 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 --all

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 foo.bar.Baz.che

pyt will consider foo.bar 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 a 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).

pyt turns on buffering and failfast by default

This is the opposite of Python’s normal unittest behavior, you can turn them off with --no-buffer and --no-failfast flags, respectively.

The --debug flag is really handy, it will print out each test that pyt runs and how long it took to run it, and how many tests it will run in total.

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:

project/
  __init__.py
  user.py
  foo/
    __init__.py
    user.py
  tests/
    __init__.py
    user_test.py
    foo/
      __init__.py
      user_test.py

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

$ pyt user

it will run both tests/user_test and tests.foo.user_test, 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.

Installation

Use pip:

$ pip install pyt

You can also get it directly from the repo:

$ pip install git+https://github.com/Jaymon/pyt#egg=pyt

License

MIT

Release files for pyt 0.7.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyt 0.7.24
File Size Uploaded
pyt-0.7.24.tar.gz 8.9 kB Details

Release files / pyt-0.7.24.tar.gz

Download URL pyt-0.7.24.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
da5880d6001cd6a3d9a1e3af0ad501f327de6b963a478b120f3c31637ded3f1c
BLAKE2b-256 checksum
How to use checksums
00a337ce8969a56a2d1c0b246cc11e7424c988409a985b801231bd819a11c582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.4.0

2 release files

1.3.0

2 release files

1.0.5

1 release file

0.7.31

1 release file

0.7.29

1 release file

0.7.28

1 release file

0.7.27

1 release file

0.7.26

1 release file

0.7.25

1 release file

This release

0.7.24 This release

1 release file

0.7.23

1 release file

0.7.22

1 release file

0.7.15

1 release file

0.7.14

1 release file

0.7.13

1 release file

0.7.12

1 release file

0.7.11

1 release file

0.7.10

1 release file

0.7.9

1 release file

0.7.7

1 release file

0.7.6

1 release file

0.7.5

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.6.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page