Ticket #103 (reopened)
Run fictures (setup/teardown) only for modules or packages that contain tests
| Priority: | high | Reporter: | guest |
|---|---|---|---|
| Severity: | major | Assigned to: | jpellerin |
| Component: | nose | Status: | reopened |
| Version: | 0.9.1 | Resolution: | |
| Milestone: | 0.10 | Keywords: | defect |
Description by guest:
my directory structure:
proj/module1/__init__.py(has setup/teardown)
module1.py
proj/module2/__init__.py(has setup/teardown)
module2.py
When I run below in proj dir:
nosetests module1 -vv I found although only module1.py is running but both module1 package setup/teardown and module2's has run. that means I have to run: nosetests module1 -e module2 to exclude module2.
is there a way to run module1 package's test only? I know I could run `nosetest -w module1`, but this way can't call package setup/teardown.
Changelog
Sun Nov 12 09:33:47 2006: Modified by guest
- summary changed from Run specific module test only. to Run specific package test only.
Sun Nov 12 20:10:25 2006: Modified by jpellerin
- milestone changed from 0.9.1 to 0.9.2
- severity changed from blocker to major
- priority changed from normal to high
- keywords set to defect
- status changed from new to assigned
Mon Nov 13 14:42:13 2006: Modified by jpellerin
- resolution set to wontfix
- status changed from assigned to closed
Having reviewed this issue a bit further, I'm afraid that it's not solvable without sacrifices in performance that I'm not prepared to make.
The problem is this: the example above defines two packages. nose always descends into packages to look for tests, because many projects are arranged like:
proj/
__init__.py
foo/
__init__.py
tests/
bar/
__init__.py
tests/
However, nose doesn't want to do a depth-first search, potentially examining hundreds or thousands of files before starting on the first test. So when it sees a package, it processes a test suite that is going to start by running the package's setup (if any), and then run a TestDir?, which is another suite that discovers and loads tests from the directory. This means that for a package, the test list is never empty, even if there are no tests in the package. This means that module2's setup and teardown are going to run, though the tests in module2 are skipped (in this case because module2 isn't a test-like name). Even when I finish reorganizing module loading along the lines I've been working on today, it will only help the case where module1 and module2 are single-file modules, not where they are packages. The only way to fix this for packages would be to complete that reorganization, and then also make package searches depth-first, which I think would be prohibitively slow for large codebases.
Closing this ticket as wontfix. Please feel free to open it again if you have a suggestion for how it might be implemented without a depth-first search into packages.
Fri Nov 17 11:52:11 2006: Modified by jpellerin
- resolution cleared
- milestone changed from 0.9.2 to 0.10
- status changed from closed to reopened
Reopening and moving to 0.10 milestone. I think this will be fixable with the new loader.
Wed Dec 6 14:15:16 2006: Modified by jpellerin
- summary changed from Run specific package test only. to Run fictures (setup/teardown) only for modules or packages that contain tests

Fixing this cleanly is going to require some non-trivial refactoring of the test loader and suites, so I'm going to do it as part of an 0.9.2 release, not as a bugfix to 0.9.1. Unfortunately, until the fix appears on svn trunk at least, you'll have to continue using the workaround of adding -e module2 to the commandline. (Since there is a workaround, I don't consider this a "blocker" level bug, so I'm also downgrading the severity to major.)