Skip to main content

Module for making changes in code during runtime

Project description

Dynamic-executor library for changing python code during runtime

Dynamic python is ment to be used in test development for creating and updating tests or wherever the need arises to change the code during runtime and have results visible instantaneously without restarting. The main functionality is provided by exec_in_dynamic_mode generator that reloads all project-root modules (neither builtin not venv modules are reloaded)

Installation

You can install the dynamic-executor package using pip:

pip install dynamic-executor

Or by cloning the repository directly :

git clone git@github.com:Tesla2000/dynamic_executor.git

Example

Here's an example of how to use the exec_in_dynamic_mode function:

# ImportedModuleFaulty.py
from dynamic_executor import DynamicClass


class SomeDynamicClass(DynamicClass):
    def foo(self):
        raise ValueError
# ImportedModuleValid.py
from dynamic_executor import DynamicClass


class SomeDynamicClass(DynamicClass):
    def foo(self):
        pass
# test_executor.py
dynamic_instance.foo()
from dython import exec_in_dynamic_mode
parent = Path(__file__).parent
parent.joinpath("ImportedModule.py").write_text(
    parent.joinpath("ImportedModuleFaulty.py").read_text()
)  # faulty version of imported module
from ImportedModule import SomeDynamicClass
dynamic_instance = SomeDynamicClass()
index = -1
for index, error in enumerate(exec_in_dynamic_mode(locals(), globals(), parent.joinpath("test_executor.py"))):
    if index:
        assert False  # ensuring that the error is corrected
    parent.joinpath("ImportedModule.py").write_text(
        parent.joinpath("ImportedModuleValid.py").read_text()
    )  # correcting module

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

dynamic-executor-1.0.6.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

dynamic_executor-1.0.6-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

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