M
Michael Hoffman
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:
"""
import imp
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>
have a .py extension. This is how I am doing it now in test/test_polysub.py
which is meant to test scripts/polysub:
"""
import imp
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>