Since testcontainers-python :material-tag: v4.7.0
The Testcontainers module for testing Python module imports and package management. This module provides a containerized environment for testing various aspects of Python module imports, including:
- Basic module and package imports
- Module reloading
- Version-specific imports
- Dependencies and environment variables
- Advanced features like custom loaders and namespace packages
Please run the following command to add the Test Module Import module to your python dependencies:
pip install testcontainers[test_module_import]
The module provides several examples demonstrating different use cases:
This example demonstrates the fundamental capabilities of the TestModuleImportContainer:
- Importing a basic Python module and accessing its attributes
- Importing and using submodules
- Importing and working with packages
- Proper cleanup of imported modules
This example shows how to work with module reloading functionality:
- Importing a module and accessing its initial state
- Reloading the module to pick up changes
- Handling reloading errors gracefully
- Managing module state during reloads
This example demonstrates handling version-specific module imports:
- Importing specific versions of modules
- Managing version compatibility
- Accessing and verifying version information
- Working with version-specific features
This example shows how to handle module dependencies and environment requirements:
- Importing modules with external dependencies
- Managing required dependency versions
- Setting up and accessing environment variables
- Handling environment-specific configurations
Dependencies and environment variables
This example demonstrates advanced module import capabilities:
- Using custom module loaders for specialized import scenarios
- Working with namespace packages
- Managing entry points
- Handling complex module configurations