I'm not sure if something like this is even possible in Python, but if it is it'd be really useful (at least to me in this instance).
I have a test framework in which I want to keep the test configuration separate from the test commands. This is useful because it allows you to mix and match configurations/tests without actually having to modify any code. I essentially just a have a short runner script that takes the names of a config module and a test module, then loads and runs both, like so:
config = __import__(configmod)
test = __import__(commandsmod)
config.run(test.commands)
The only problem with this is I'd actually like the test script to have some limited awareness of the configuration parameters. Ideally I'd like to be able to do something like the following in the test/commands module:
command1 = MyCommand(arg1, arg2, LazyArg1())
command2 = MyCommand(arg1, arg2, LazyArg2())
commands = [command1, command2]
where LazyArg1 and LazyArg2 are methods that are defined in the config module (or the runner module that imports both config/commands). Is there any way to delay evaluation of these functions until they are actually defined?
I'd also be open to other ways of achieving the same end. The only other idea I had was to have the config module write a dictionary to file and then have the commands module import that (assuming you just write out repr(mydict)
). This isn't very appealing .. though it would work.