<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 04/08/2010 22:59, Jorge Vargas wrote:
<blockquote
 cite="mid:AANLkTikNKvG2ome3_O_enUPjBAxEtWvC2akVbksYkZn+@mail.gmail.com"
 type="cite">Hi,
  <div><br>
  </div>
  <div>I'm trying to decouple a package from it's deployed environment.
In order to make it testable. For this I need to change some hardcoded
paths currently defined at module level things in the form&nbsp;</div>
  <div><br>
  </div>
  <div>PATH_TO_SCRIPTS = '/var/lib/..../'</div>
  <div><br>
  </div>
  <div>in production those files must be present and the build process
takes care of that. However in development and testing I will like to
have those paths be different.</div>
  <div><br>
  </div>
  <div>I could override those at import time but it will mean having to
override the variable on each test module.&nbsp;</div>
  <div><br>
  </div>
  <div>therefore I think a better solution will be to&nbsp;pollute&nbsp;the
package a little with a flag to check this.</div>
  <div><br>
  </div>
  <div>I'm thinking of something like</div>
  <div><br>
  </div>
  <div>PATH_TO_SCRIPTS = '/this/value/will/never/be'</div>
  <div><br>
  </div>
  <div>if &lt;running in testing&gt;:</div>
  <div>&nbsp;&nbsp; &nbsp;PATH_TO_SCRIPTS = '../some_checkout'</div>
  <div>else:</div>
  <div>&nbsp;&nbsp; &nbsp;PATH_TO_SCRIPTS = '/var/lib/...../'</div>
  <div><br>
  </div>
  <div>this will be at my module.__init__.py which means everything
should work with either path specified as long as they contain some
scripts.</div>
  <div><br>
  </div>
  <div>Bonus points if someone could point out how to add a third flag
to&nbsp;differentiate&nbsp;from development and testing.</div>
  <div><br>
  </div>
  <div>BTW this is with unittest2 although I think the solution should
be valid for all other testing tools. <br>
  </div>
</blockquote>
<br>
In general having runtime behaviour that is different between tests and
deployment is generally a bad idea. Hardcoding paths is also generally
a bad idea. Perhaps you can solve both by using some form of
configuration?<br>
<br>
Michael Foord<br>
<br>
<br>
<blockquote
 cite="mid:AANLkTikNKvG2ome3_O_enUPjBAxEtWvC2akVbksYkZn+@mail.gmail.com"
 type="cite">
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (&#8221;BOGUS AGREEMENTS&#8221;) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

</pre>
</body>
</html>