Package: neatest
neatestEasy-to-use unit test runner.Simplifies discovery ofunittest.TestCasetests in the projectRuns tests with standardunittestTesting can be started from the shell with a single-word command:neatestTesting can be customized by python scripts callingneatest.run(...)neatestcan replace many runs ofpython -m unittest discover ...command.
The priority forneatestis full compatibility and interchangeability with
the standardunittest. Tests that can be run fromneatestcan also
be run withunittestwithout any project modification.Supports Python 3.7+ on Linux, macOS and Windows.Installpip3installneatestProject layoutneatestdiscovers all classes inherited fromunittest.TestCasewithin the
project. Test cases can be placed inany .py fileinsideany directory.
If you prefer to keep test cases in the "tests" directory with filenames
starting with "test", they will be discovered, because they are also "any
files in any directory".You can use a simple project layout:my_simple_project
    __init__.py     # tests can be placed here
    test_a.py       # tests can be placed here
    test_b.py       # tests can be placed here
    anything.py     # tests can be placed hereor a project with multiple packages:my_complex_project
    package_a
        __init__.py         # tests can be placed here
        any_files.py        # tests can be placed here
        can_contain.py      # tests can be placed here
        tests_inside.py     # tests can be placed here
        ...
    package_b
        __init__.py         # tests can be placed here
        ...
    tests  
        __init__.py         # tests can be placed here
        test_something.py   # tests can be placed here
        test_anything.py    # tests can be placed hereSubdirectories must beimportableas packages from the project directory.They are importable, when you can$cdmy_complex_project
$python3and then in Pythonimportpackage_aimportpackage_bimporttestsRunRun tests from command line$cdmy_complex_project
$neatestPackage "package_a" contains 3 tests
Package "package_b" contains 4 tests
Package "tests" contains 16 tests
.....
----------------------------------------------------------------------
Ran 23 tests in 2.947s

OKAdd some options:$cdmy_complex_project
$neatest--start-directorytests--verboseSee all possible options:$neatest--helpRun tests from .py scriptCreate a scriptFor example,run_tests.py:importneatestneatest.run()Run the script$cdmy_complex_project
$python3path/to/run_tests.pyThe idea is to use single.pyscript to run the tests (instead of.sh,.bator.cfg).
Python scripts are readable, and they are portable as the Python itself.You can specify all the options available toneatestcommand-line tool as
arguments toneatest.runmethod:importneatestneatest.run(start_directory="tests",verbosity=neatest.Verbosity.verbose)Argumentstests_requireYou can specify dependencies to be installed withpip installbefore testing.
These dependencies are presumably missing fromrequirements.txtandsetup.pyas they are not needed in production.neatest.run(tests_require=['requests','lxml'])$neatest-rrequests-rlxmlThis is the equivalent of the deprecated argumenttests_requirefromsetuptools.setup.warningsBy default, warnings caught during testing are printed to the stdout.warnings: ignoreIn this mode warnings will not be displayed.neatest.run(warnings=neatest.Warnings.ignore)$neatest--warningsignorewarnings: failIn this mode warnings will be treated as errors. If at least one warning appears
during testing, it will cause the testing to fail (with exception or non-zero
return code).neatest.run(warnings=neatest.Warnings.fail)$neatest--warningsfailTest discoveryFilenamesneatestsearches for tests in all*.pyfiles.The same can be achieved with standardunittestlike this:$python3-munittestdiscover-p"*.py"Directoriesneatestassumes, that the current directory is the project directory. It is
the base directory for all imports.If thestart_directoryare not specified,neatestwill find all the packages
inside the project directory and will run tests for each of them.my_project
    package_a               # tests in package_a will be discovered
        __init__.py
    package_b               # tests in package_b will be discovered
        __init__.py
    package_c               # tests in package_c will be discovered
        __init__.py
        subpackage          # subpackage is a part of package_c 
            __init__.py     # so tests will be discovered
            ...
    subdir                  # subdir is not a package
        package_d           # tests in package_d will NOT be discovered  
            __init__.py     # because package_d is not importable    
  setup.pySo the commands$cdmy_project
$neatestwill run the same tests as$cdmy_project
$python3-munittestdiscover-t.-spackage_a-p"*.py"$python3-munittestdiscover-t.-spackage_b-p"*.py"$python3-munittestdiscover-t.-spackage_c-p"*.py"