summaryrefslogtreecommitdiff
path: root/testtools/tests
Commit message (Collapse)AuthorAgeFilesLines
* Fix distutilscmd in Debian + Py 3.11Thomas Goirand2022-12-271-2/+2
| | | | | | | | | | Under Debian, when attempting to run tests, the debian folder is found and conflicts with this error: setuptools.errors.PackageDiscoveryError: Multiple top-level packages discovered in a flat-layout: ['debian', 'testtools']. This patch fixes this (I already applied it in Debian, and it solved the issue for me).
* Prevent AttributeError in TestCase.__eq__Tim Burke2022-11-041-0/+5
| | | | Not all objects have a __dict__ attribute.
* Making sure that TestCase can be hashedBen Beecher2022-07-011-0/+4
|
* Fix various test failures with Python 3.11Colin Watson2022-07-013-13/+16
| | | | | | | | | | | The changes for https://peps.python.org/pep-0657/ require a number of changes in our tests. Some tests still fail due to https://twistedmatrix.com/trac/ticket/10336, so I'm not adding 3.11 to the test matrix yet. Fixes #325.
* Merge branch 'master' into rm-3.5Hugo van Kemenade2022-06-066-17/+17
|\
| * Fix DeprecationWarning: Only valid in 1.8.1 and earlier. Use skipTest instead.Hugo van Kemenade2022-06-046-8/+8
| |
| * Replace deprecated assertRaisesRegexp with assertRaisesRegexHugo van Kemenade2022-06-041-10/+10
| |
* | Merge branch 'master' into rm-3.5Hugo van Kemenade2022-05-043-9/+13
|\ \ | |/
| * Upgrade asserts with teyit for Python 3.11 compatibilityHugo van Kemenade2022-02-073-33/+37
| |
* | Upgrade Python syntax with pyupgrade --py36-plusHugo van Kemenade2022-02-079-48/+47
|/
* Add support for Python 3.10Jürgen Gmach2021-10-141-1/+4
|
* Fix for Python 3.10Hugo van Kemenade2021-06-261-0/+2
|
* Fix tests with Python 3.10Cyril Roelandt2021-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | In Python 3, error messages have become a bit more precise. For instance, the following code snippet: ---- class Foo(): def bar(self, a): pass try: Foo().bar(1, 2) except TypeError as e: print(e) ---- will return: - in Python 3.9: "bar() takes 2 positional arguments but 3 were given" - in Python 3.10: "Foo.bar() takes 2 positional arguments but 3 were given" Fix our tests accordingly.
* trivial: Cleanup importsStephen Finucane2021-02-259-28/+18
| | | | | | | This is kept separately from the reintroduction of 'try_imports' to keep that patch reasonable. Signed-off-by: Stephen Finucane <stephen@that.guru>
* Re-introduce 'try_imports'Stephen Finucane2021-02-2510-10/+10
| | | | | | | | | | | | There are few if any people still (knowingly) using the 'extras' lib. OpenStack users have their own implementation (sigh) in 'oslo.utils' and everyone else is getting by with try-except statements. Reintroduce this utility to 'testtools.helpers', allowing us to eventually drop the dependency on extras. Note however that we can't actually do this yet since 'fixtures' has an implicit dependency on 'extras' through 'testtools', and we break that by removing it here. Signed-off-by: Stephen Finucane <stephen@that.guru>
* Remove use of 'try_imports'Stephen Finucane2021-02-252-8/+8
| | | | | | | | This was being used in places to handle differences between Python 2 and Python 3. Since we only care about the latter now, the utility can be removed. Signed-off-by: Stephen Finucane <stephen@that.guru>
* Remove use of 'safe_hasattr'Stephen Finucane2021-02-252-7/+2
| | | | | | | | | | | | | This was used to workaround some issues with 'hasattr' on Python 2.x versions, discussed in the source for extras (where this utility was moved to make it more useful to others) [1] and elsewhere on the internet [2]. These issues are no longer present on the versions of Python we now support (Python 3.6+) so this is no longer necessary. [1] https://github.com/testing-cabal/extras/blob/1.0.0/extras/__init__.py#L101-L108 [2] https://hynek.me/articles/hasattr/ Signed-off-by: Stephen Finucane <stephen@that.guru>
* Merge remote-tracking branch 'origin/master' into remove-unittest2Matthew Treinish2020-07-081-0/+3
|\
| * Fix syntax error test for Python 3.9Michel Alexandre Salim2020-05-161-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Python 3.9 the zero-width no-break space Unicode character U+FEFF does not get printed in syntax errors. See: https://bugzilla.redhat.com/show_bug.cgi?id=1831126 This is reproducible in a virtual environment as well. Before: ``` .venv ❯ make check PYTHONPATH=/home/michel/src/github/testing-cabal/testtools python -m testtools.run testtools.tests.test_suite /usr/lib64/python3.9/runpy.py:127: RuntimeWarning: 'testtools.run' found in sys.modules after import of package 'testtools', but prior to execution of 'testtools.run'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) Tests running... ====================================================================== FAIL: testtools.tests.test_testresult.TestNonAsciiResults.test_syntax_error_line_utf_8 ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/michel/src/github/testing-cabal/testtools/testtools/tests/test_testresult.py", line 2744, in test_syntax_error_line_utf_8 self.assertThat( File "/home/michel/src/github/testing-cabal/testtools/testtools/testcase.py", line 499, in assertThat raise mismatch_error testtools.matchers._impl.MismatchError: 'Tests running...\n======================================================================\nERROR: test_syntax_error_line_utf_8.Test.runTest\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File "/tmp/TestNonAsciiResultsblblh75h/test_syntax_error_line_utf_8.py", line 6, in runTest\n import bad\n File "/tmp/TestNonAsciiResultsblblh75h/bad.py", line 1\n \ufeff^ = 0 # paɪθən\n ^\nSyntaxError: invalid syntax\n\nRan 1 test in 0.001s\nFAILED (failures=1)\n' does not match /.*bad.py", line 1\n\s*\^ = 0 # pa\u026a\u03b8\u0259n\n \s*\^\nSyntaxError:.*/ ====================================================================== FAIL: testtools.tests.test_testresult.TestNonAsciiResultsWithUnittest.test_syntax_error_line_utf_8 ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/michel/src/github/testing-cabal/testtools/testtools/tests/test_testresult.py", line 2744, in test_syntax_error_line_utf_8 self.assertThat( File "/home/michel/src/github/testing-cabal/testtools/testtools/testcase.py", line 499, in assertThat raise mismatch_error testtools.matchers._impl.MismatchError: 'E\n======================================================================\nERROR: runTest (test_syntax_error_line_utf_8.Test)\ntest_syntax_error_line_utf_8.Test.runTest\n----------------------------------------------------------------------\ntesttools.testresult.real._StringException: Traceback (most recent call last):\n File "/tmp/TestNonAsciiResultsWithUnittest_zzswpmj/test_syntax_error_line_utf_8.py", line 6, in runTest\n import bad\n File "/tmp/TestNonAsciiResultsWithUnittest_zzswpmj/bad.py", line 1\n \ufeff^ = 0 # paɪθən\n ^\nSyntaxError: invalid syntax\n\n\n----------------------------------------------------------------------\nRan 1 test in 0.000s\n\nFAILED (errors=1)\n' does not match /.*bad.py", line 1\n\s*\^ = 0 # pa\u026a\u03b8\u0259n\n \s*\^\nSyntaxError:.*/ Ran 2627 tests in 0.569s FAILED (failures=2) make: *** [Makefile:7: check] Error 1 ``` After: ``` .venv ❯ make check PYTHONPATH=/home/michel/src/github/testing-cabal/testtools python -m testtools.run testtools.tests.test_suite /usr/lib64/python3.9/runpy.py:127: RuntimeWarning: 'testtools.run' found in sys.modules after import of package 'testtools', but prior to execution of 'testtools.run'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) Tests running... Ran 2627 tests in 0.492s OK ```
* | Merge branch 'master' into remove-unittest2Matthew Treinish2020-04-0429-478/+475
|\ \ | |/
| * Merge branch 'master' into rm-2Hugo van Kemenade2020-03-191-0/+87
| |\
| | * Merge branch 'master' into skip-classZane Bitter2020-01-142-9/+15
| | |\
| | * | Allow skip/skipIf/skipUnless as class decoratorsZane Bitter2018-11-191-0/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In unittest/unittest2 the skip/skipIf/skipUnless decorators can be used to decorate either individual test methods or entire TestCase classes. However, the testtools equivalents could previously only be used to decorate test methods. If used on a TestCase the class would be replaced with a function, resulting in the tests either not be discovered at all or (if a custom test loader was used) potentially an error. This change allows the skip decorators to be used on the TestCase subclass, for equivalent functionality with unittest. Fixes #205 Signed-off-by: Zane Bitter <zbitter@redhat.com>
| | * | Get rid of Python 2.4 support from skip decoratorZane Bitter2018-11-191-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All of the python versions we support have functools.wraps(), so there is no need to have a soft import for it any more (indeed, we use it unconditionally elsewhere). Also, avoid modifying the attributes of the function passed in and relying on functools.wraps() to copy them to the function we're actually returning. Just add the attributes to the substitute function and return it as the user is probably expecting. Signed-off-by: Zane Bitter <zbitter@redhat.com>
| * | | Drop support for EOL Python 2.7Hugo2020-01-181-7/+2
| | | |
| * | | Remove sixHugo2020-01-181-2/+0
| | | |
| * | | Upgrade Python syntax with pyupgrade --py3-plusHugo2020-01-1820-98/+98
| | | |
| * | | Remove redundant Python 2 compatability codeHugo2020-01-1815-230/+148
| | | |
| * | | Upgrade Python syntax with pyupgradeHugo2020-01-1816-152/+151
| | |/ | |/|
* | | Merge branch 'master' into remove-unittest2Jelmer Vernooij2019-11-282-9/+15
|\ \ \ | |/ /
| * | Extra space expected in PyPy outputHugo2019-11-251-1/+6
| | |
| * | Don't use eval()Ross Burton2018-11-221-8/+9
| |/ | | | | | | | | | | | | eval() has security implications so security scanners such as Bandit warn about the use of eval(). In the context of the test suite where eval() is used there are no security problems, but changing to ast.literal_eval is trivial so do it anyway.
* | Remove unittest2 usage from testtoolsMatthew Treinish2019-05-035-12/+11
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently testtools bases all of it's unittest extensions off of unittest2 instead of the stdlib unittest. At one point this made sense since unittest2 provided a stable base as unittest in stdlib added features. But it's been ~5 years since there was a unittest2 release (or a patch merged) and things have changed since then. The best example of this is of the supported python versions listed in the unittest2 project description/README only one is still supported by upstream python, 2.7, which goes end of life at the end of this year. More specific to testtools the use of unittest2 causes a whole slew of issues because of differences in behavior with stdlib unittest. For example here a couple issues encountered: https://bugs.launchpad.net/testtools/+bug/1467558 https://bugs.launchpad.net/testtools/+bug/1417803 mtreinish/stestr#238 testing-cabal/testtools#272 which are caused, at least in part, by unittest2. There are likely other bugs related to it that haven't been reported (or I just missed/forgot about). At this point it's better to remove the unittest2 usage and just rely on the upstream stdlib unittest which if nothing else is actively maintained. It'll improve compatibility using the testtools runner with stdlib unittest test suites and removes the class of bugs caused by the differences in unittest2. Fixes #263
* Fix the tests on Python 3.7Miro Hrončok2018-05-171-2/+9
| | | | | | Exception's repr got changed not to include trailing comma Fixes https://github.com/testing-cabal/testtools/issues/270
* Drop support for EOL Python 3.3Hugo2018-05-031-1/+1
|
* Remove old Python 2.6 codehugovk2018-01-091-11/+0
|
* Spelling fixes (#261)Ville Skyttä2017-05-292-7/+7
|
* Python 3.6 invalid escape sequence deprecation fixes (#262)Ville Skyttä2017-05-293-10/+10
| | | https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
* Add ResourcedToStreamDecorator test result decorator for testresources ↵Free Ekanayaka2017-04-111-2/+75
| | | | | integration (#243) This new decorator implements the TestResult protocol extension supported by test resources. For example, tt makes it possible to easily have resource-related events streamed to subunit.
* Make KeysEqual usable with no arguments, i.e. match a dict with no keys. (#241)Gavin Panella2017-03-171-0/+24
| | | | Make KeysEqual usable with no arguments, i.e. match a dict with no keys.
* Don't add file details without content (#252)Thomas Hervé2017-02-081-0/+12
| | | | | In the test record API, skip adding file details to the record if there are not bytes. This reduces that amount of data kept when there is none.
* Make twistedsupport and tests work on Python 3remove-test-dependency-on-twisted-13Free Ekanayaka2016-11-261-3/+3
|
* Add matchers for detecting emitted warnings.Jonathan Jacobs2016-03-162-0/+205
|
* Add unique_text_generatorBrant Knudson2016-02-291-1/+48
| | | | | | | | | This provides a way to make it easier to test with unicode text strings. The value returned will be like TestCase.getUniqueString but the value is six.text_type and contains unicode. Change-Id: I3f144e1294a801b23793f7a2520465e15f3a5222
* Become compatible with newer Fixtures _setUp() API.Julian Edwards2016-02-151-2/+38
| | | | | | | | | Previously, when gathering details caused by a setUp failure, a traceback occurred if the fixture used the newer _setUp(). This also had the side effect of not clearing up fixtures properly. Change-Id: I9d138e8d559e176867c6e3f4b89f784cf4d29f05 Fixes: https://bugs.launchpad.net/testtools/+bug/1469759
* Better handling of KeyboardInterruptJonathan Lange2016-02-141-4/+4
| | | | | | When we get a suspected KeyboardInterrupt (no result from Deferred), explicitly stop the result and report the error as if it were a user error.
* Move all Twisted code to twistedsupport packageJonathan Lange2016-02-077-36/+65
| | | | | | | | | * Move test code to testtools.tests.twistedsupport, to parallel matchers * Add testtools.deferredruntest to preserve backwards compatibility * Move NeedsTwistedTestCase out of test_spinner into shared module for Twisted tests Closes #202
* Revert "Move all Twisted code to twistedsupport package"Jonathan Lange2016-02-077-59/+36
| | | | | | This reverts commit e571d9c25ff280a21bb879a9c4c264ef233dc9a2. Travis CI was failing before merge.
* Move all Twisted code to twistedsupport packageJonathan Lange2016-02-077-36/+59
| | | | | | | * Move test code to testtools.tests.twistedsupport, to parallel matchers * Add testtools.deferredruntest to preserve backwards compatibility * Move NeedsTwistedTestCase out of test_spinner into shared module for Twisted tests
* Add Always & Never matchers.Jonathan Lange2016-02-072-0/+33
|