[kwlug-disc] Python tests in a subfolder

Steve Izma sizma at golden.net
Mon Apr 17 23:17:03 EDT 2017


On Mon, Apr 17, 2017 at 05:48:57PM -0400, Paul Nijjar wrote:
> Subject: Re: [kwlug-disc] Python tests in a subfolder
> 
> On Mon, Apr 17, 2017 at 05:25:10PM -0400, Steve Izma wrote:
> 
> ... 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. 

Well, I'm glad that works, but it seems upside down to me. Why
not put the scripts that are likely to be reused by "test"
scripts in the sub-directory, as if it were a lib or module
directory? That is, your working directory is the parent and
re-usable stuff is in various subdirectories, suitably named.
If you were re-using xml parsers and utilities, put them in a sub
dir; if you have specialized database tools put them in a subdir
named db, etc.; then:

import xml.utils
import db.getfields

On the other hand, perhaps I misunderstand how you want to
organize things.

	-- 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