Commit Graph

16 Commits

Author SHA1 Message Date
Serhiy Storchaka 3c8a5b459d
bpo-40275: Avoid importing asyncio in test.support (GH-19600)
* Import asyncio lazily in unittest (only when IsolatedAsyncioTestCase is used).
* Import asyncio.events lazily in test.support.
2020-04-25 10:04:10 +03:00
Andrew Svetlov 4dd3e3f9bb bpo-32972: Async test case (GH-13386)
Add explicit `asyncSetUp` and `asyncTearDown` methods.
The rest is the same as for #13228

`AsyncTestCase` create a loop instance for every test for the sake of test isolation.
Sometimes a loop shared between all tests can speed up tests execution time a lot but it requires control of closed resources after every test finish. Basically, it requires nested supervisors support that was discussed with @1st1 many times. Sorry, asyncio supervisors have no chance to land on Python 3.8.

The PR intentionally does not provide API for changing the used event loop or getting the test loop: use `asyncio.set_event_loop_policy()` and `asyncio.get_event_loop()` instead.

The PR adds four overridable methods to base `unittest.TestCase` class:
```
    def _callSetUp(self):
        self.setUp()

    def _callTestMethod(self, method):
        method()

    def _callTearDown(self):
        self.tearDown()

    def _callCleanup(self, function, /, *args, **kwargs):
        function(*args, **kwargs)
```
It allows using asyncio facilities with minimal influence on the unittest code.

The last but not least: the PR respects contextvars. The context variable installed by `asyncSetUp` is available on test, `tearDown` and a coroutine scheduled by `addCleanup`.


https://bugs.python.org/issue32972
2019-05-29 02:33:59 -07:00
Lisa Roach 0f221d09ca
bpo-24412: Adds cleanUps for setUpClass and setUpModule. (GH-9190) 2018-11-08 18:34:33 -08:00
Berker Peksag aa5c2fdb7c Issue #28303: Fix grammar in unittest.__doc__, patch by Shlomi Fish 2016-09-28 17:28:41 +03:00
Brett Cannon 07b954d148 Add some "used with permission" mentions where external resources are referenced.
Permission was validated prior to adding these markings.
2016-01-15 09:53:51 -08:00
Robert Collins bf2bda3c97 Close #22457: Honour load_tests in the start_dir of discovery.
We were not honouring load_tests in a package/__init__.py when that was the
start_dir parameter, though we do when it is a child package. The fix required
a little care since it introduces the possibility of infinite recursion.
2014-11-05 03:09:01 +13:00
Mark Dickinson 51ef074d57 Docstring typo fix: Arithmentic -> Arithmetic. 2013-09-09 10:34:24 +01:00
Michael Foord de4ceabfd8 Merged revisions 80476 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80476 | michael.foord | 2010-04-25 20:02:46 +0100 (Sun, 25 Apr 2010) | 1 line

  Adding unittest.removeHandler function / decorator for removing the signal.SIGINT signal handler. With tests and docs.
........
2010-04-25 19:53:49 +00:00
Michael Foord 65b69a1093 Merged revisions 79437 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79437 | michael.foord | 2010-03-26 03:18:31 +0000 (Fri, 26 Mar 2010) | 1 line

  Addition of -c command line option to unittest, to handle ctrl-c during a test run more elegantly
........
2010-03-27 13:25:41 +00:00
Benjamin Peterson eab4b4c784 Merged revisions 79274 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79274 | michael.foord | 2010-03-21 21:49:08 -0500 (Sun, 21 Mar 2010) | 1 line

  Correct usage message displayed for python -m unittest -h
........
2010-03-22 02:53:52 +00:00
Benjamin Peterson dccc1fcfaf Merged revisions 79263 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79263 | michael.foord | 2010-03-21 19:06:30 -0500 (Sun, 21 Mar 2010) | 1 line

  Issue 7815. __unittest in module globals trims frames from reported stacktraces in unittest.
........
2010-03-22 00:15:53 +00:00
Benjamin Peterson 847a4110ea Merged revisions 78227,78229,78288,78348,78377,78770,78774-78776,78810 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78227 | michael.foord | 2010-02-18 14:30:09 -0600 (Thu, 18 Feb 2010) | 1 line

  unittest.TestCase uses safe_repr for producing failure messages. Partial fix for issue 7956
........
  r78229 | michael.foord | 2010-02-18 15:37:07 -0600 (Thu, 18 Feb 2010) | 1 line

  Fix unittest.TestCase.assertDictContainsSubset so it can't die with unicode issues when constructing failure messages. Issue 7956
........
  r78288 | michael.foord | 2010-02-21 08:48:59 -0600 (Sun, 21 Feb 2010) | 1 line

  Silence UnicodeWarning in crazy unittest test.
........
  r78348 | michael.foord | 2010-02-22 17:28:32 -0600 (Mon, 22 Feb 2010) | 1 line

  Support for old TestResult object (unittest) with warnings when using unsupported features.
........
  r78377 | michael.foord | 2010-02-23 11:00:53 -0600 (Tue, 23 Feb 2010) | 1 line

  unittest.TestResult can now be used with the TextTestRunner. TextTestRunner compatible with old TestResult objects.
........
  r78770 | michael.foord | 2010-03-07 14:22:12 -0600 (Sun, 07 Mar 2010) | 1 line

  Fix for potentials errors in constructing unittest failure messages. Plus skipped test methods no longer run setUp and tearDown (Issue 8059)
........
  r78774 | michael.foord | 2010-03-07 16:04:55 -0600 (Sun, 07 Mar 2010) | 1 line

  Addition of setUpClass and setUpModule shared fixtures to unittest.
........
  r78775 | michael.foord | 2010-03-07 17:10:36 -0600 (Sun, 07 Mar 2010) | 1 line

  Fix accidental name rebinding in unittest py3k warning filtering.
........
  r78776 | michael.foord | 2010-03-07 17:16:20 -0600 (Sun, 07 Mar 2010) | 1 line

  Remove accidental print statement from last commit.
........
  r78810 | raymond.hettinger | 2010-03-09 02:44:18 -0600 (Tue, 09 Mar 2010) | 5 lines

  Improve the basic example.
  * Show both the decorator and regular form for assertRaises()
  * Use assertTrue() instead of assertIn() to teach useful minimal subset of the API
........
2010-03-14 15:04:17 +00:00
Michael Foord cb468b4427 Merged revisions 78158 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78158 | michael.foord | 2010-02-11 14:12:07 +0000 (Thu, 11 Feb 2010) | 1 line

  Adding TextTestResult to unittest.__all__
........
2010-02-11 14:16:38 +00:00
Michael Foord 34c9462d71 Merged revisions 78130 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78130 | michael.foord | 2010-02-10 14:25:12 +0000 (Wed, 10 Feb 2010) | 1 line

  Issue 7893 and Issue 7588
........
2010-02-10 15:51:42 +00:00
Benjamin Peterson 46a9900e09 Merged revisions 77209,77229,77359-77360,77371 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77209 | georg.brandl | 2010-01-01 07:07:05 -0600 (Fri, 01 Jan 2010) | 1 line

  More yearly updates.
........
  r77229 | georg.brandl | 2010-01-02 06:35:01 -0600 (Sat, 02 Jan 2010) | 1 line

  Fix casing.
........
  r77359 | georg.brandl | 2010-01-07 14:54:45 -0600 (Thu, 07 Jan 2010) | 1 line

  Fix description for Py_GetPath(); it sounded like it always returned sys.path.
........
  r77360 | georg.brandl | 2010-01-07 15:48:47 -0600 (Thu, 07 Jan 2010) | 1 line

  #7653: clarify how the PythonPath registry key should look like.
........
  r77371 | senthil.kumaran | 2010-01-08 13:20:25 -0600 (Fri, 08 Jan 2010) | 3 lines

  Fix for Issue7026. For the Error - RuntimeError: dictionary changed size during iteration
........
2010-01-09 18:45:30 +00:00
Benjamin Peterson bed7d04fed Merged revisions 74095 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74095 | benjamin.peterson | 2009-07-19 15:18:21 -0500 (Sun, 19 Jul 2009) | 1 line

  split unittest.py into a package
........
2009-07-19 21:01:52 +00:00