yeukhon / testcapture

(INCUBATOR! CODE ARE MESSY) A simple Python program that allows statements and expressions within a test function body to be recorded and replay at later time by using Python's AST module to rewrite the test code.
0 stars 0 forks source link

How to load a module into namespace from compile() #11

Open yeukhon opened 10 years ago

yeukhon commented 10 years ago

We get back ast nodes after rewriting the nodes, then we feed to compile(..) but we get back a code obj. We want to actually just import the module from this code obj so we can pull out, say, the classes and module constants.

Right now, we are going to write the modified ast to source code in a temporary file and execute that file. That's a quick solution and will work without pulling hair about how to deal with namespace and such. But it will be an interesting problem to ask how to get the ast nodes into a module object.