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.

Why?

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):
    pass

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:

$ _IMPALL_WARNINGS_ACTION=error pytest

Using impall.py as a standalone program

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

$ impall.py [directory ..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:

$ impall.py --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.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

impall-1.1.1-py2.py3-none-any.whl (6.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file impall-1.1.1.tar.gz.

File metadata

  • Download URL: impall-1.1.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

File hashes

Hashes for impall-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d8949092e4aa7f015f9d605d6f531108f21afb154ad55c43b30cb8b6a651945d
MD5 0daa138de909bb80205580197a2a8a2b
BLAKE2b-256 825fc4b4c780dba71a68617b8bfd2c975e9f5f24472fccb88c689ac1de1f2773

See more details on using hashes here.

File details

Details for the file impall-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: impall-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

File hashes

Hashes for impall-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b0467d6c0ed97598090a1a8cdc5a7f058d6149342e3058702da6aa582b92f0d7
MD5 9e36e6565b067866e9f75a55d5926050
BLAKE2b-256 b5081eed84c28d3a16d045205577893f3c9bf84dffcf9067c76fb7367a574ea5

See more details on using hashes here.

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