unittest and non-.py files

  • Thread starter Michael Hoffman
  • Start date
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>
 
S

Sybren Stuvel

Michael Hoffman enlightened us with:
Hi. I am trying to use unittest to run a test suite on some
scripts that do not have a .py extension.

I'd move the functionality of the script into a separate file that
does end in .py, and only put the invocation into the .py-less
script.

Sybren
 
M

Michael Hoffman

[Michael Hoffman]
[Sybren Stuvel]
I'd move the functionality of the script into a separate file that
does end in .py, and only put the invocation into the .py-less
script.

That's what I have done, and it is a better solution for other reasons.
Thanks Sybren.

I would still like to do what I originally proposed. Would this warrant
a feature request?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,677
Latest member
MoisesKoeh

Latest Threads

Top