
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2013-01-11 14:43 bybrett.cannon, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue16935.diff | zach.ware,2013-01-28 19:48 | Allow SkipTest to be raised at module level during discovery | review | |
| issue16935.v2.diff | zach.ware,2013-02-11 16:54 | Version 2, with test and doc change | review | |
| issue16935.v3.diff | zach.ware,2013-02-25 18:29 | Version 3 | review | |
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 2502 | merged | vstinner,2017-06-30 10:38 | |
| PR 2505 | merged | vstinner,2017-06-30 10:56 | |
| PR 2506 | merged | vstinner,2017-06-30 10:57 | |
| Messages (20) | |||
|---|---|---|---|
| msg179681 -(view) | Author: Brett Cannon (brett.cannon)*![]() | Date: 2013-01-11 14:43 | |
For test discovery to work where a dependent module is optional, you end up needing to do something like what is done inhttp://hg.python.org/cpython/rev/15ddd683c321:-crypt = support.import_module('crypt')+def setUpModule():+ # this import will raise unittest.SkipTest if _crypt doesn't exist,+ # so it has to be done in setUpModule for test discovery to work+ global crypt+ crypt = support.import_module('crypt')That's kind of ugly. It would be better if unittest recognized SkipTest at import time during test discovery | |||
| msg179682 -(view) | Author: Michael Foord (michael.foord)*![]() | Date: 2013-01-11 14:44 | |
Agreed and it should be easy to implement. | |||
| msg179700 -(view) | Author: Éric Araujo (eric.araujo)*![]() | Date: 2013-01-11 16:29 | |
FTR there is already an alternative to setupmodule:try: import moduleexcept ImportError: module = None@unittest.skipUnless(module, 'requires module')class ModuleTests(unittest.TestCase): passThis idiom is more lines than support.import_module, but works for non-stdlib tests too, and is useful when you don’t want the whole file to be skipped if the module is missing (like in distutils’ test_sdist where zlib can be missing). | |||
| msg179770 -(view) | Author: Ezio Melotti (ezio.melotti)*![]() | Date: 2013-01-12 05:34 | |
FWIW the difference between support.import_module and the try/except/skip is that usually the former is used when *all* the tests require the imported module, whereas the latter is used when only some of the tests requires it. | |||
| msg179903 -(view) | Author: Chris Jerdonek (chris.jerdonek)*![]() | Date: 2013-01-14 00:06 | |
Without the proposed enhancement, you could also combine Éric's approach with the original patch by doing something like:try: support.import_module(module)except SkipTest: module = Nonedef setUpModule(): if module is None: raise SkipTest() | |||
| msg179904 -(view) | Author: Chris Jerdonek (chris.jerdonek)*![]() | Date: 2013-01-14 00:08 | |
Should be: "module = support.import_module('module')" | |||
| msg179946 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2013-01-14 16:01 | |
Still, raising SkipTest from the toplevel is useful when some toplevel setup code otherwise depends on the missing module. | |||
| msg179952 -(view) | Author: Zachary Ware (zach.ware)*![]() | Date: 2013-01-14 16:34 | |
I agree that raising SkipTest (or subclasses thereof, such as ResourceDenied) at module level should be supported. That would mean no changes would be needed in most of the should-be-skipped-but-fail-instead tests listed inissue 16748 to make test discovery play nicely, and in fact the changes to test_crypt could be mostly reverted.Personally, I don't find either of the suggestions given as alternates to what I did in test_crypt to be particularly prettier, not that what I did is pretty either. | |||
| msg180877 -(view) | Author: Zachary Ware (zach.ware)*![]() | Date: 2013-01-28 19:48 | |
Here's a patch that I believe nicely handles the raising of unittest.SkipTest at module level while doing test discovery. It adds a _make_skipped_test function to unittest.loader, and an ``except case.SkipTest`` clause to TestLoader._find_tests. For our own test package, this covers non-enabled resources as well.Here's some example output:"""P:\cpython>python -m unittest discover -vLib/test/ "test_curs*"test_curses (unittest.loader.ModuleSkipped) ... skipped "Use of the 'curses' resource not enabled"----------------------------------------------------------------------Ran 1 test in 0.001sOK (skipped=1)[102289 refs, 38970 blocks]""" | |||
| msg181864 -(view) | Author: Michael Foord (michael.foord)*![]() | Date: 2013-02-11 00:32 | |
The patch looks good - can you add a test and documentation for this? | |||
| msg181902 -(view) | Author: Zachary Ware (zach.ware)*![]() | Date: 2013-02-11 15:53 | |
Sure can. With a little luck, I'll have the patch ready later today; with less luck it'll be sometime later this week. | |||
| msg181909 -(view) | Author: Zachary Ware (zach.ware)*![]() | Date: 2013-02-11 16:54 | |
I think this patch should cover the test and Doc changes necessary. Of course, let me know if it doesn't :) | |||
| msg182969 -(view) | Author: Zachary Ware (zach.ware)*![]() | Date: 2013-02-25 18:29 | |
Thanks for the review, Ezio. I've made some changes and here's the new patch. | |||
| msg183122 -(view) | Author: Ezio Melotti (ezio.melotti)*![]() | Date: 2013-02-27 08:16 | |
LGTM. | |||
| msg183256 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2013-03-01 12:48 | |
New changeset61ce6deb4577 by Ezio Melotti in branch 'default':#16935: unittest now counts the module as skipped if it raises SkipTest, instead of counting it as an error. Patch by Zachary Ware.http://hg.python.org/cpython/rev/61ce6deb4577 | |||
| msg183257 -(view) | Author: Ezio Melotti (ezio.melotti)*![]() | Date: 2013-03-01 12:49 | |
Applied, thanks for the patch!SkipTest should probably be documented, but that's a separate issue :) | |||
| msg183258 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2013-03-01 12:54 | |
New changeset22b6b59c70e6 by Ezio Melotti in branch 'default':#16935: update test_crypt now that unittest discover understands SkipTest.http://hg.python.org/cpython/rev/22b6b59c70e6 | |||
| msg297375 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2017-06-30 10:52 | |
New changesete4f9a2d2be42d5a2cdd624f8ed7cdf5028c5fbc3 by Victor Stinner in branch 'master':bpo-30813: Fix unittest when hunting refleaks (#2502)https://github.com/python/cpython/commit/e4f9a2d2be42d5a2cdd624f8ed7cdf5028c5fbc3 | |||
| msg297385 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2017-06-30 11:12 | |
New changeset714afccf6e7644d21ce1a39e90bf83cb0c9a74f1 by Victor Stinner in branch '3.5':bpo-30813: Fix unittest when hunting refleaks (#2502) (#2506)https://github.com/python/cpython/commit/714afccf6e7644d21ce1a39e90bf83cb0c9a74f1 | |||
| msg297389 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2017-06-30 11:12 | |
New changeset22d4e8fb99b16657eabfe7f9fee2d40a5ef882f6 by Victor Stinner in branch '3.6':bpo-30813: Fix unittest when hunting refleaks (#2502) (#2505)https://github.com/python/cpython/commit/22d4e8fb99b16657eabfe7f9fee2d40a5ef882f6 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:40 | admin | set | github: 61139 |
| 2017-06-30 11:39:51 | pitrou | set | nosy: -pitrou |
| 2017-06-30 11:12:24 | vstinner | set | messages: +msg297389 |
| 2017-06-30 11:12:18 | vstinner | set | messages: +msg297385 |
| 2017-06-30 10:57:33 | vstinner | set | pull_requests: +pull_request2576 |
| 2017-06-30 10:56:28 | vstinner | set | pull_requests: +pull_request2572 |
| 2017-06-30 10:52:55 | vstinner | set | nosy: +vstinner messages: +msg297375 |
| 2017-06-30 10:38:06 | vstinner | set | pull_requests: +pull_request2565 |
| 2013-03-01 12:54:47 | python-dev | set | messages: +msg183258 |
| 2013-03-01 12:49:23 | ezio.melotti | set | status: open -> closed messages: +msg183257 assignee:michael.foord ->ezio.melotti keywords: -gsoc resolution: fixed stage: test needed -> resolved |
| 2013-03-01 12:48:08 | python-dev | set | nosy: +python-dev messages: +msg183256 |
| 2013-02-27 08:16:55 | ezio.melotti | set | messages: +msg183122 |
| 2013-02-25 18:29:12 | zach.ware | set | files: +issue16935.v3.diff messages: +msg182969 |
| 2013-02-11 16:54:08 | zach.ware | set | files: +issue16935.v2.diff messages: +msg181909 |
| 2013-02-11 15:53:45 | zach.ware | set | messages: +msg181902 |
| 2013-02-11 00:32:48 | michael.foord | set | messages: +msg181864 |
| 2013-01-28 19:48:07 | zach.ware | set | files: +issue16935.diff keywords: +patch messages: +msg180877 |
| 2013-01-14 22:10:17 | asvetlov | set | nosy: +asvetlov |
| 2013-01-14 16:34:47 | zach.ware | set | messages: +msg179952 |
| 2013-01-14 16:01:23 | pitrou | set | nosy: +pitrou messages: +msg179946 |
| 2013-01-14 00:08:42 | chris.jerdonek | set | messages: +msg179904 |
| 2013-01-14 00:06:27 | chris.jerdonek | set | nosy: +chris.jerdonek messages: +msg179903 |
| 2013-01-13 21:43:08 | Arfrever | set | nosy: +Arfrever |
| 2013-01-12 05:34:59 | ezio.melotti | set | nosy: +ezio.melotti messages: +msg179770 |
| 2013-01-11 16:29:12 | eric.araujo | set | nosy: +eric.araujo messages: +msg179700 |
| 2013-01-11 14:57:59 | zach.ware | set | nosy: +zach.ware |
| 2013-01-11 14:44:05 | michael.foord | set | keywords: +gsoc messages: +msg179682 |
| 2013-01-11 14:43:08 | brett.cannon | create | |