[kwlug-disc] Python tests in a subfolder

Steve Izma sizma at golden.net
Mon Apr 17 17:25:10 EDT 2017


On Mon, Apr 17, 2017 at 05:09:10PM -0400, Paul Nijjar via kwlug-disc wrote:
> Subject: [kwlug-disc] Python tests in a subfolder
> 
> I have the following directory structure: 
> 
> project_folder:
> - my_script.py
> - config.py
> - tests/
>   + test_script.py
> 
> my_script.py is a simple script with a few helper functions. It is not
> meant to be a module. 
> 
> I am trying to set up pytest so that it will be able to see and run
> the helper functions in my_script.py . But I do not understand what
> structure I need. There is the following question: 
> 
> http://stackoverflow.com/questions/26804421
> 
> but that makes it seem as if I have to turn my_script.py into a
> module. Running that setuptools command near the bottom of the answer
> creates a gross my_package.egg-info folder in the root folder of my
> project. 

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.

Whatever you're doing with config.py probably requires similar
treatment.

More typically, you put any script that you want to import into
the py-site directory. On Debian it's usually:
/usr/local/lib/py-site-packages

	-- Steve

-- 
Steve Izma
-
Home: 35 Locust St., Kitchener, Ontario, Canada  N2H 1W6
E-mail: sizma at golden.net  phone: 519-745-1313  cell: 519-998-2684

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
<http://en.wikipedia.org/wiki/Posting_style>





More information about the kwlug-disc mailing list