This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest discover should allow option to run each package separately
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, michael.foord, the.mulhern
Priority: normal Keywords:

Created on 2014-04-02 12:21 by the.mulhern, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg215380 - (view) Author: the mulhern (the.mulhern) Date: 2014-04-02 12:21
You can run "python -m unittest discover <some args>" and the unittests discovered by discover will be run. This is nice.

However, it is actually desirable to run each unittest package individually, rather than in the same interpreter instance. When run via discover, imports from previous unittests corrupt the namespace of subsequent unittests and lead to failures (usually if there are mock objects in previously imported unit tests) and successes (usually if some other test module has imported something that the current test module ought to import but does not) which are both erroneous.

discover should have some option to start the interpreter afresh for each unittest package or perhaps just clear all its imports.
msg215565 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-04-04 21:16
> imports from previous unittests corrupt the namespace of subsequent unittests and lead to failures
> (usually if there are mock objects in previously imported unit tests)

Can you tell more about this?  I haven’t run into this issue with large test suites that use mocks (and mock.path monkey-patching) heavily (probably because mock.patch is active for one test method only).
msg215580 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-05 00:09
This is only an issue if a test package pollutes its environment without cleaning up (puts mocks in place that it doesn't remove for example). Fixing this would require discover to use multiple processes to run tests, which isn't going to happen (at least not soon). A better fix is to have test clean up after themselves properly.
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65332
2014-04-05 00:09:58michael.foordsetstatus: open -> closed
resolution: wont fix
messages: + msg215580

stage: resolved
2014-04-04 21:16:43eric.araujosetnosy: + eric.araujo, michael.foord

messages: + msg215565
versions: - Python 3.1, Python 2.7, Python 3.2, Python 3.3, Python 3.4
2014-04-02 12:21:40the.mulherncreate