nose-devs/nose — Issue #248: Modules that import tests sometimes get the imported module's fixtures
Author: jpellerin
Created: 2011-12-14 16:05:15+00:00
State: closed

What steps will reproduce the problem?
1. Unpack nose_package_fixture_confusion.tar.gz
2. Run nosetests -xs package2f
3. Run nosetests -xs package2c

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

Since the "package2*" packages both import exactly one test from package1,
I expected them to run the same set of fixtures. They don't:

$ nosetests -xs package2f
package2f setup
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
$ nosetests -xs package2c
package2c setup
package1 setup
.
----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

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

svn revision 414 on OS X 10.4

Please provide any additional information below.

When a package imports tests from another package, the imported module's
fixtures will only be run in some conditions. If the imported test was a
class, they will; if it was a function, they won't. I found this very
confusing.

I have a rough idea of why this happens. ContextSuite.setUp goes back
through the ancestors of the current context, looking for setup and
teardown functions. I don't quite understand why, but class tests seem to
capture their definition contexts while function tests don't.

I guess this might be the intended behavior, but I found it quite
confusing. It took me a long time to even reproduce it, since I kept using
function tests in an attempt to keep the examples simple. Of course, the
function tests didn't show the problem and I thought I was going crazy.

I'm not sure how (or if) it could be "fixed", or even whether it should be.
Maybe some kind of warning would help. (Does nose ever emit warnings?) I
guess I'm just wondering whether this behavior is expected - maybe my
expectations were just off.

Google Code Info:
Issue #: 145
Author: gary.ber...@gmail.com
Created On: 2008-01-04T23:01:41.000Z
Closed On: 2008-04-02T02:44:30.000Z