pythonwhat
pythonwhat copied to clipboard
ability switch evaluated code environment to module
Currently, pythonwhat uses subprocesses for evaluated student / solution. For cases where a main script imports a custom module that is part of an exercise, it would be useful to set the module as the "environment". For example, in the code below we may want to check config
, even if __main__.py
is the script executed by the process.
__main__.py
:
from app import app
app.py
:
from somelibrary import load_config, Service
config = load_config(...)
app = Service(config)
SCT sketch
(Ex()
.check_file('app.py')
.set_module_env('app') # exposes variables in module "app"
.test_object('config')
)