testing -- what to do for testing code with behaviour dependant upon which files exist?

Brian van den Broek bvande at po-box.mcgill.ca
Mon Apr 4 19:37:06 EDT 2005


Jeremy Bowers said unto the world upon 2005-04-04 17:26:
> On Mon, 04 Apr 2005 17:02:20 -0400, Brian van den Broek wrote:
> 
>>Jeremy suggested using a directory name akin to 
>>"C:\onlyanidiotwouldhavethisdirecotrynameonadrive". That is what I had 
>>settled on before I posted. Somehow it feels unhappy and inelegant. 
>>But, I'm a bit less uncomfortable with it seeing that others have done 
>>so, too.
> 
> 
> To be clear, I would actually suggest
> "onlyanidiotwouldhavethisdirecotrynameonadrive"... note the lack of C:\,

Quite so. My apologies for mis-characterizing your suggestion. And 
thanks for the additional information that mis-characterization 
provoked :-)

Best,

Brian vdB

> which would be platform specific, as would any other root specification.
> Take advantage of the fact that every system I know of makes relative
> directories easy, and also note you can work out what directory the
> "current file" is in with a combination of __file__ and os.getcwd() (and
> that while that won't work if someone changes the working directory,
> that's bad form and IIRC breaks some other things in Python as well, so
> don't do that). 
> 
> Making it a relative directory may make it look just as bad, but it is in
> some sense somewhat less inelegant; at that point, if someone is creating
> that directory in the test directory of your app, they're just fooling
> with you, and you don't really have to worry about people who maliciously
> make your unit tests fail under most circumstances... :-)





More information about the Python-list mailing list