Skip to main content

Runs standard unittest discovery and testing, requiring less rain dance.

Project description

neatest

Runs standard Python unittest discovery and testing. Provides a more convenient way of configuring the tests.

It replaces the shell command python -m unittest discover ... with a brief programmatic call from Python code.

Why

Testing should be simple. One line command. A really short line.

python -m unittest discover ... is too long.

run_tests.sh is better. But not pythonic and not cross-platform.

run_tests.py is much better.

For example, if your command looks like this

$ cd project_dir && python -m unittest discover -s ./mymodule -p '*_test.py' --buffer

you can replace it with run_tests.py:

import neatest
neatest.pattern = "*_test.py"
neatest.start_dir = "./module"
neatest.run()

This script can be run with python3 run_tests.py. Now the command is short and cross-platform.

Install

pip3 install neatest

Run

Run tests with .py script

project_dir / run_tests.py

import neatest

# optionally setting parameters
neatest.pattern = '*_test.py'
neatest.verbocity = 2

if __name__ == "__main__":
    neatest.run()

Terminal

$ python3 run_tests.py

Run tests with setup.py

project_dir / run_tests.py

import neatest

# optionally setting parameters. 
# Setup.py will only respect parameters related to
# the test discovery (TestSuite initialization)
neatest.pattern = '*_test.py'  # will be used
neatest.verbocity = 2          # will be ignored 

project_dir / setup.py

setup(
  ...
  test_suite='run_tests.neatest.suite',
)

Terminal

$ cd project_dir
$ python3 setup.py test

Differences from "-m unittest discover"

pattern

neatest searches for tests in all *.py files. Any TestCase in the code is considered a test to be run.

Standard unittest discover searches only for tests in files named test*.py.

start_dir

If not specified, neatest find the first directory containing __init__.py and consider it the starting directory.

It works well with package structure like that:

project_dir
  my_module
    tests
      __init__.py
      test_a.py
      test_b.py 
    __init__.py
    code1.py
    code2.py
  setup.py

It doesn't matter what the current directory is project_dir or my_module: neatest will search for the tests inside my_module.

Standard unittest discover assumes that the starting directory is the current directory. If run from the project_dir it will not find any tests, unless you explicitly specify that the starting directory is my_module.

For neatest to behave as standard, just set neatest.start_dir="."

buffer

stdout and stderr will be buffered by default.

Standard unittest discover requires --buffer argument for that.

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

neatest-0.0.3.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

neatest-0.0.3-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

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