title: Python Packages?
body: <p>Ok, I think whatever I'm doing wrong, it's probably blindingly obvious, but I can't figure it out. I've read and re-read the tutorial section on packages and the only thing I can figure is that this won't work because I'm executing it directly. Here's the directory setup:</p>
  
  <pre><code>eulerproject/
    __init__.py
    euler1.py
    euler2.py
    ...
    eulern.py
    tests/
      __init__.py
      testeulern.py
  </code></pre>
  
  <p>Here are the contents of testeuler12.py (the first test module I've written):</p>
  
  <pre><code>import unittest
  from .. import euler12
  
  class Euler12UnitTests(unittest.TestCase):
  
  
      def testtriangle(self):
          """
          Ensure that the triangle number generator returns the first 10
          triangle numbers.
  
          """
          self.seq = [1,3,6,10,15,21,28,36,45,55]
          self.generator = euler12.trianglegenerator()
          self.results = []
          while len(self.results) != 10:
              self.results.append(self.generator.next())
          self.assertEqual(self.seq, self.results)
  
      def testdivisors(self):
          """
          Ensure that the divisors function can properly factor the number 28.
  
          """
          self.number = 28
          self.answer = [1,2,4,7,14,28]
          self.assertEqual(self.answer, euler12.divisors(self.number))
  
  
  if __name__ == '__main__':
  
      unittest.main()
  </code></pre>
  
  <p>Now, when I execute this from IDLE and from the command line while in the directory, I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Documents and Settings\jbennet\My Documents\Python\eulerproject\tests\testeuler12.py", line 2, in &lt;module&gt;
      from .. import euler12
  ValueError: Attempted relative import in non-package
  </code></pre>
  
  <p>I think the problem is that since I'm running it directly, I can't do relative imports (because <code>__name__</code> changes, and my vague understanding of the packages description is that <code>__name__</code> is part of how it tells what package it's in), but in that case what do you guys suggest for how to import the 'production' code stored 1 level up from the test code?</p>