[kwlug-disc] Python tests in a subfolder
Paul Nijjar
paul_nijjar at yahoo.ca
Mon Apr 17 17:48:57 EDT 2017
On Mon, Apr 17, 2017 at 05:25:10PM -0400, Steve Izma wrote:
>
> I don't think you need to do anything with my_script.py except
> put it somewhere in your PYTHONPATH. It's automatically found if
> it's in the same directory as the program that calls it, so if
> you have:
>
> tests/
> + test_script.py
> + my_script.py
>
> then, in test_script.py:
>
> import my_script
>
> should give you everything defined in my_script.py. Note that you
> don't use the suffix in the import command.
Yes, this is how I import config.py . But I do not want the tests and
the script in the same folder. I want the tests in a subfolder, and
then I want the tests to find the script. So I have to change the
PYTHONPATH somehow?
[type type type]
Okay, that works. In my test file, I have:
import sys, os
sys.path.insert(0, os.path.abspath(os.pardir))
which adds the parent folder to the PYTHONPATH.
--
http://pnijjar.freeshell.org
More information about the kwlug-disc
mailing list