https://github.com/rec/impall
🛎 Test-import all modules 🛎
https://github.com/rec/impall
python testing testing-tools tools
Last synced: about 1 month ago
JSON representation
🛎 Test-import all modules 🛎
- Host: GitHub
- URL: https://github.com/rec/impall
- Owner: rec
- License: mit
- Created: 2019-03-27T17:14:50.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T18:25:09.000Z (over 2 years ago)
- Last Synced: 2025-04-08T23:35:42.700Z (about 1 year ago)
- Topics: python, testing, testing-tools, tools
- Language: Python
- Homepage: https://rec.github.io/impall/
- Size: 706 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELIST
- Funding: FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🛎 Test-import all modules 🛎
Individually and separately imports each Python module or file in a project and
reports warnings or failures at the end.
### Running impall as a unit test
Just inherit from the base class and it will
automatically find and import each file, like this.
import impall
class ImpAllTest(impall.ImpAllTest):
pass
(You can copy
[this file](https://github.com/rec/impall/blob/master/all_test.py)
into your project if you like.)
Tests are customized by overriding one of these following properties in the
derived class.
CLEAR_SYS_MODULES, EXCLUDE, FAILING, INCLUDE, MODULES, PATHS,
RAISE_EXCEPTIONS, and WARNINGS_ACTION.
For example, to turn warnings into errors, set the property
WARNINGS_ACTION in the derived class definition, like this.
class ImpAllTest(impall.ImpAllTest):
WARNINGS_ACTION = 'error'
## Running impall as a command-line utility
$ impall --warnings_action=error
$ impall -w error
The properties INCLUDE, EXCLUDE, and PROJECT_PATH can be
lists of strings, or a string separated with colons like
'foo.mod1:foo.mod2'
INCLUDE and EXCLUDE match modules, and also allow * as a wildcard.
A single * matches any module segment, and a double ** matches any
remaining segments. For example,
`INCLUDE = 'foo', 'bar.*', 'baz.**'`
* matches `foo` but not `foo.foo`
* matches `bar.foo` but not `bar` or `bar.foo.bar`
* matches `baz.foo` as well as `baz.foo.bar` but not `baz`
### A note on side-effects
to reduce side-effects, `sys.modules` is restored to its original
condition after each import if CLEAR_SYS_MODULES is true, but there might be
other side-effects from loading some specific module.
Use the EXCLUDE property to exclude modules with undesirable side
effects. In general, it is probably a bad idea to have significant
side-effects just from loading a module.
### [API Documentation](https://rec.github.io/impall#impall--api-documentation)