pombreda / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

setup_package is not called sometimes in python2.7rc1 #342

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 <module 'foo' from '/tmp/repro/foo/__init__.py'> 
does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests' from 
'/tmp/repro/foo/tests/__init__.py'> does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests.test_a' from 
'/tmp/repro/foo/tests/test_a.py'> does need setup
nose.suite: DEBUG: ancestor <class 'foo.tests.test_a.TestFoo'> does need setup

$ pwd
/tmp/repro
$ nosetests -vvv 2>&1 | grep "does need setup"
nose.suite: DEBUG: ancestor <module 'bar' from '/tmp/repro/bar/__init__.py'> 
does need setup
nose.suite: DEBUG: ancestor <module 'foo' from '/tmp/repro/foo/__init__.py'> 
does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests' from 
'/tmp/repro/foo/tests/__init__.py'> does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests.test_a' from 
'/tmp/repro/foo/tests/test_a.py'> does need setup
nose.suite: DEBUG: ancestor <class 'foo.tests.test_a.TestFoo'> 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 <module 'foo' from '/tmp/repro/foo/__init__.py'> 
does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests' from 
'/tmp/repro/foo/tests/__init__.py'> does need setup
nose.suite: DEBUG: ancestor <module 'foo.tests.test_a' from 
'/tmp/repro/foo/tests/test_a.py'> does need setup
nose.suite: DEBUG: ancestor <class 'foo.tests.test_a.TestFoo'> does need setup

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

Original issue reported on code.google.com by jls....@gmail.com on 10 Jun 2010 at 9:58

GoogleCodeExporter commented 9 years ago
I'm also having similar problems with setup_class() as of Py2.7.  If I run 
SQLAlchemy unit tests as:

   nosetests -v

where the test modules are all under test/, no setup_class() is called for any 
test and I get 1400 failures.

If I OTOH run them as:

   nosetests -v -w test/

then it's fine.

Original comment by zzz...@gmail.com on 5 Jul 2010 at 11:31

GoogleCodeExporter commented 9 years ago
Issue 350 has been merged into this issue.

Original comment by jpelle...@gmail.com on 6 Jul 2010 at 1:07

GoogleCodeExporter commented 9 years ago

Original comment by jpelle...@gmail.com on 6 Jul 2010 at 1:07

GoogleCodeExporter commented 9 years ago
This is fixed in stable. Once selftest is passing for 2.7 (numerous 
doctest-related failures to diagnose), expect a 0.11.4.

Original comment by jpelle...@gmail.com on 7 Jul 2010 at 2:01

GoogleCodeExporter commented 9 years ago

Original comment by jpelle...@gmail.com on 7 Jul 2010 at 4:22