pythonwhat icon indicating copy to clipboard operation
pythonwhat copied to clipboard

ability switch evaluated code environment to module

Open machow opened this issue 7 years ago • 0 comments

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')
     )

machow avatar Dec 28 '17 17:12 machow