nose-devs/nose — Issue #16: setup_package is not called sometimes in python2.7rc1
Author: jpellerin
Created: 2011-12-14 15:55:05+00:00
State: open

What steps will reproduce the problem?

1. Create a directory structure like this:
|-- bar
| |-- __init__.py
| `-- tests
| `-- __init__.py
`-- foo
|-- __init__.py
`-- tests
|-- __init__.py
`-- test_a.py

2. In foo/tests/__init__.py add this:
MYLIST = []

def setup_package():
MYLIST.append(1)

3. In foo/tests/test_a.py add this:
import unittest
import foo.tests

class TestFoo(unittest.TestCase):
def test1(self):
self.assertEqual(len(foo.tests.MYLIST), 1,
"Package level setup not called!")

4. If I cd into foo/ and run nosetests I get:
$ pwd
/tmp/repro/foo
$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

5. If I go up one directory and run nosetests I get:

$ pwd
/tmp/repro
$ nosetests
F
======================================================================
FAIL: test1 (foo.tests.test_a.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/repro/foo/tests/test_a.py", line 7, in test1
"Package level setup not called!")
AssertionError: Package level setup not called!

----------------------------------------------------------------------
Ran 1 test in 0.011s

FAILED (failures=1)

What is the expected output? What do you see instead?

In python 2.5, I get 1 passing test in both steps 4 and 5. In python2.7 the test will only pass if you are in the foo/ directory.

What version of the product are you using? On what operating system?

WORKING: nose=0.11.3, OS=debian, python=2.5.4
NOTWORKING: nose=0.11.3, OS-debian, python 2.7rc1

Please provide any additional information below.

In python 2.5 I get this:

$ pwd
/tmp/repro/foo
$ nosetests -vvv 2>&1 | grep "does need setup"
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup

$ pwd
/tmp/repro
$ nosetests -vvv 2>&1 | grep "does need setup"
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup

In python 2.7 I get this:
$ pwd
/tmp/repro/foo
$ nosetests -vvv 2>&1 | grep "does need setup"
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup
nose.suite: DEBUG: ancestor does need setup

$ pwd
/tmp/repro
$ nosetests -vvv 2>&1 | grep "does need setup"
$

Google Code Info:
Issue #: 342
Author: jls....@gmail.com
Created On: 2010-06-10T21:58:48.000Z
Closed On: 2010-07-07T16:22:40.000Z