Skip to main content

Try to import all modules below a given root

Project description

A three-line unit test in your project automatically imports every Python file and module in it, optionally testing for warnings.


Not every file is covered by unit tests; and unit tests won’t report any new warnings that occur.

impall is a single-file library with a unit test that automatically imports every Python file and module in your project.

I drop include_all into each new project. It takes seconds, it inevitably catches lots of dumb problems early, and it requires no maintenance.

How to use impall

Install it with pip install impall, and use it by adding this tiny file (raw) anywhere in a project - it looks like this:

import impall

class ImpAllTest(impall.ImpAllTest):

and most of the time that’s all you need.

Overriding properties

ImpAllTest has eight properties that can be overridden.

  • CLEAR_SYS_MODULES: If True, sys.modules is reset after each import.

  • EXCLUDE: A list of modules that will not be imported at all.

  • FAILING: A list of modules that must fail.

  • INCLUDE: If non-empty, exactly the modules in the list will be loaded.

  • MODULES: If False, search all subdirectories.

  • PATHS: A list of paths to search from.

  • RAISE_EXCEPTIONS: If True, stop importing at the first exception

  • WARNINGS_ACTION: One of: default, error, ignore, always, module, once

Full documentation for each property is here.

To permanently override a test property, set it in the derived class, like this:

import impall

class ImpAllTest(impall.ImpAllTest):
    WARNINGS_ACTION = 'error'

To temporarily override a test property, set an environment variable before runnning the test, like this:


Using as a standalone program

The file is executable and is installed in the path by pip. You can use it on projects that you are evaluating or debugging like this:

$ [directory]

where if no directory is specified it uses the current directory.

You can use environment variables to set properties as above and for convenience there are also command line flags for each property, so you can write:

$ --catch_exceptions --all_directories --exclude=foo/bar

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

impall-1.1.0.tar.gz (10.0 kB view hashes)

Uploaded source

Built Distribution

impall-1.1.0-py3-none-any.whl (10.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page