unittest and non-.py files
cam.ac.uk at mh391.invalid
Wed Dec 7 23:56:20 CET 2005
Hi. I am trying to use unittest to run a test suite on some scripts that do not
have a .py extension. This is how I am doing it now in test/test_polysub.py
which is meant to test scripts/polysub:
from path import path as Path
SCRIPTNAME = "polysub"
test_dirpath = Path(__file__).parent
script_filepath = test_dirpath.joinpath("..", "scripts", SCRIPTNAME).normpath()
script = imp.load_source(SCRIPTNAME, script_filepath)
Then I can call functions from within the script in my unittest.
The problem is that imp.load_source() compiles the script first, making a file
called "polysubc" which I do not want. Is there a better solution?
And even if there is a better solution, can you please tell me of a way to load
the script as a module without generating the "polysubc" file? No points for
telling me to use python -O so I get "polysubo" instead. <wink>
More information about the Python-list