unittest2 1.1.0
pip install unittest2
Released:
The new features in unittest backported to Python 2.4+.
Navigation
Unverified details
These details havenot been verified by PyPIProject links
Meta
- License: BSD License (UNKNOWN)
- Author:Robert Collins
- Tags unittest, testing, tests
Classifiers
- Development Status
- Environment
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
Project description
unittest2 is a backport of the new features added to the unittest testingframework in Python 2.7 and onwards. It is tested to run on Python 2.6, 2.7,3.2, 3.3, 3.4 and pypy.
To use unittest2 instead of unittest simply replaceimport unittest withimport unittest2.
unittest2 is maintained in a mercurial repository. The issue tracker is ongoogle code:
Thanks to Mark Roddy, there is a distribution of unittest2 0.5.1 for Python 2.3.This is maintained as a separate branch and is a separate download.
To avoid problems withpip installing the wrong distribution, the Python 2.3version of unittest2 can’t be hosted on PyPI:
There was a separate version of unittest2 for Python 3. This is no longerneeded, but still exists on PyPI. This had the project name “unittest2py3k” butuses the same package name (“unittest2”):
Classes in unittest2 derive from the appropriate classes in unittest, so itshould be possible to use the unittest2 test running infrastructure withouthaving to switch all your tests to using unittest2 immediately. Similarlyyou can use the new assert methods onunittest2.TestCase with the standardunittest test running infrastructure. Not all of the new features in unittest2will work with the standard unittest test loaders, runners result objectshowever.
In general for documentation on unittest2 see the current latest documented ofCPython:
New features include:
addCleanups - better resource management
many new assert methods including better defaults for comparing lists,sets, dicts unicode strings etc and the ability to specify new default methodsfor comparing specific types
assertRaises as context manager, with access to the exception afterwards
test discovery and new command line options (including failfast and betterhandling of ctrl-C during test runs)
class and module level fixtures:setUpClass,tearDownClass,setUpModule,tearDownModule
test skipping and expected failures
newdelta keyword argument toassertAlmostEqual for more usefulcomparison and for comparing non-numeric objects (like datetimes)
load_tests protocol for loading tests from modules or packages
startTestRun andstopTestRun methods on TestResult
various other API improvements and fixes
Note
Command line usage
In Python 2.7 you invoke the unittest command line features (including testdiscover) withpython-m unittest <args>. As unittest is a package, andthe ability to invoke packages withpython-m ... is new in Python 2.7,we can’t do this for unittest2.
Instead unittest2 comes with a scriptunit2.Command line usage:
unit2 discoverunit2 -v test_module
There is also a copy of this script calledunit2.py, useful for Windowswhich uses file-extensions rather than shebang lines to determine whatprogram to execute files with. Both of these scripts are installed bydistutils.
Until I write proper documentation, the best information on all the new featuresis the development version of the Python documentation for Python 2.7:
Look for notes about features added or changed in Python 2.7.
Note
unittest2 is already in use for development ofdistutils2.
Version 0.5.1 of unittest2 has feature parity withunittest in Python 2.7final. If you want to ensure that your tests run identically under unittest2and unittest in Python 2.7 you should use unittest2 0.5.1.
Later versions of unittest2 include changes in unittest made in Python 3.2and onwards after the release of Python 2.7.
Differences
Differences between unittest2 and unittest in Python 2.7:
assertItemsEqual does not silence Py3k warnings as this useswarnings.catch_warnings() which is new in Python 2.6 (and is used as acontext manager which would be a pain to make work with Python 2.4).
TestCase.longMessage defaults to True because it is better. It defaults toFalse in Python 2.7 for backwards compatibility reasons.
python-m package doesn’t work in versions of Python before Python 2.7. Thecommand line features of unittest2 are provided by aunit2 (andunit2.py) script instead.
unittest2 includes a very basic setuptools compatible test collector. Specifytest_suite = 'unittest2.collector' in your setup.py. This starts testdiscovery with the default parameters from the directory containing setup.py, soit is perhaps most useful as an example (see unittest2/collector.py).
In unittest2 TextTestResult.stopTestRun is responsible for calling printErrors.This is desirable behaviour but in Python 3.1 TestResult.stopTestRun wasdocumented as being empty and subclasses shouldn’t need to call it. This wouldmake the change backwards incompatible and needs thinking about.
Issues
ATestResult object with unexpected successes returns Trueforresult.wasSuccessful(). Difficult to know if this is the correctbehaviour or not.
If a dotted path name is used for test discovery then a globally installedmodule/package will still be used in preference of one in the currentdirectory. When doing discovery from a dotted path name we could check for thisspecific case.
TheremoveHandler decorator could also be a context manager.
Issue 8313:, <unprintable AssertionError object>message in unittest tracebacks, is hard to fix in versions of Python before 2.7.The fix in Python 2.7 relies on changes to both the traceback module andtraceback objects. As the issue is rare I am leaving it unfixed in unittest2.
There are several places in unittest2 (and unittest) that callstr(...) onexceptions to get the exception message. This can fail if the exception wascreated with non-ascii unicode. This is rare and I won’t address it unless it isactually reported as a problem for someone.
A comparison of text or long sequences (usingassertSequenceEqual orassertMultiLineEqual etc) can take along time to generate diffs forfailure messages. These methods useprettyprint anddifflib.
pip install-e . on Python3.2 in the unittest2 source will fail unlesssetuptools > 0.6.24 is already installed. This is a combination of needing anewer setuptools (to avoid the use of execfile) and setup_requires falling backto easy_install that doesn’t know how to upgrade setuptools just-in-time thatprevents it being fixed in unittest2.
CHANGELOG
2015-06-20 - 1.1.0
Issue #15836: assertRaises(), assertRaisesRegex(), assertWarns() andassertWarnsRegex() assertments now check the type of the first argumentto prevent possible user error. Based on patch by Daniel Wagner-Hall.
Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() andassertWarnsRegex() checks now emits a deprecation warning when callable isNone or keyword arguments except msg is passed in the context manager mode.
Issue #22903: The fake test case created by unittest.loader when it failsimporting a test module is now picklable.
2015-03-12 - 1.0.1
Unittest2 issue #94: Need at least 1.4 of six.
2015-03-06 - 1.0.0
Issue #22936: Permit showing local variables in tracebacks.
2014/11/05 - 0.8
Issue #22457: Honour load_tests in the start_dir of discovery.
Issue #22894: TestCase.subTest() would cause the test suite to be stoppedwhen in failfast mode, even in the absence of failures.
2014/10/31 - 0.7.1
Fix for 0.7.0 being broken. Also switches from both manual and entrypointscripts to just entrypoint scripts to reduce the possibility of similaroversights in future.
2014/10/31 - 0.7.0
This release contains backports from cPython 3.5 of all (I think) commits since2010, as of today.
2014/10/28 - 0.6.0
Many thanks to Mark Roddy and Ezio Melotti who contributed substantially tothis release.
Changed supported Python versions to start at 2.6, and include all released 3.xand pypy. (Robert Collins)
Invokingunit2 without args starts test discovery
AddedTestCase.assertWarns andTestCase.assertWarnsRegexp context managers
Fix Python issue 9926. TestSuite subclasses that override __call__ are calledcorrectly.
Removed unusedmaxDiff parameter fromTestCase.assertSequenceEqual.
DeprecationWarning for unsupported result objects (missing addSkip method)became RuntimeWarning.
Addition ofTestCase.assertWarns as a context manager.
2010/07/12 - 0.5.1
Reverted script names created by setuptools back to “unit2” instead of“unit2.py”. (Not necessary as setuptools creates stub .exes for console scriptsanyway.)
2010/07/11 - 0.5.0
Addition of a setuptools compatible test collector (very basic). Specifytest_suite = 'unittest2.collector' in your setup.py.
TestSuite.debug() andTestCase.debug() now execute cleanup functionsand class and module level setups and teardowns.
No longer monkey-patch os.path.relpath for Python 2.4 / 2.5 so that projectsdon’t accidentally depend on our patching. Contributed by Konrad Delong.
Added a Python version specific unit2 entrypoint. This will, for example,create aunit2-2.6 script if unittest2 is installed with Python 2.6.(Requires setuptools or distribute.)
Python 2.3 compatibility (in the python2.3 branch of the repository),contributed by Mark Roddy.
setuptools console script entry points are created as ‘.py’ scripts on Windows.
Feature parity with the Python 2.7 final release.
2010/06/06 - 0.4.2
Improved help message forunit2 discover-h.
SkipTest in unittest.TestCase.setUpClass or setUpModule is now reported as askip rather than an error.
Excessively large diffs due toTestCase.assertSequenceEqual are nolonger included in failure reports. (Controlled byTestCase.maxDiff.)
Matching files during test discovery is done inTestLoader._match_path. Thismethod can be overriden in subclasses to, for example, match on the full filepath or use regular expressions for matching.
Addition of a setuptools compatible entrypoint for the unit2 test runner script.Contributed by Chris Withers.
Tests fixed to be compatible with Python 2.7, where deprecation warnings aresilenced by default.
Feature parity with unittest in Python 2.7 RC 1.
2010/05/09 - 0.4.1
If test discovery imports a module from the wrong location (usually because themodule is globally installed and the user is expecting to run tests against adevelopment version in a different location) then discovery halts with anImportError and the problem is reported.
Added docstrings toassertRegexpMatches andassertNotRegexpMatches.
Putting functions in test suites no longer crashes.
Feature parity with unittest in Python 2.7 Beta 2.
2010/04/08 - 0.4.0
Addition ofremoveHandler for removing the control-C handler.
delta keyword argument forassertAlmostEqual andassertNotAlmostEqual.
Addition of -b command line option (andTestResult.buffer) for bufferingstdout / stderr during test runs.
Addition ofTestCase.assertNotRegexpMatches.
Allow test discovery using dotted module names instead of a path.
All imports requiring the signal module are now optional, for compatiblitywith IronPython (or other platforms without this module).
Tests fixed to be compatible with nosetest.
2010/03/26 - 0.3.0
assertSameElements removed andassertItemsEqual added; assert thatsequences contain the same elements.
Addition of -f/–failfast command line option, stopping test run on firstfailure or error.
Addition of -c/–catch command line option for better control-C handling duringtest runs.
AddedBaseTestSuite, for use by frameworks that don’t want to support sharedclass and module fixtures.
Skipped test methods no longer havesetUp andtearDown called aroundthem.
Faultyload_tests functions no longer halt test discovery.
Using non-strings for failure messages now works.
Potential forUnicodeDecodeError whilst creating failure messages fixed.
Split out monolithic test module into a package.
BUGFIX: Correct usage message now shown for unit2 scripts.
BUGFIX:__unittest in module globals trims frames from that module inreported stacktraces.
2010/03/06 - 0.2.0
TheTextTestRunner is now compatible with old result objects and standard(non-TextTestResult)TestResult objects.
setUpClass /tearDownClass /setUpModule /tearDownModule added.
2010/02/22 - 0.1.6
Fix for compatibility with oldTestResult objects. New tests can now be runwith nosetests (with a DeprecationWarning forTestResult objects withoutmethods to support skipping etc).
0.1
Initial release.
TODO
DocumentSkipTest,BaseTestSuite`
Release process
1. Make sure there is an entry in the Changelog in this document.1. Update __version__ in unittest2/__init__.py1. Commit.1. Create a tag for the version (e.g.hg tag 0.6.0)1. Push so there is no outstanding patches and no room for races.1. Runmake release to build an sdist and wheel and upload to pypi.
Project details
Unverified details
These details havenot been verified by PyPIProject links
Meta
- License: BSD License (UNKNOWN)
- Author:Robert Collins
- Tags unittest, testing, tests
Classifiers
- Development Status
- Environment
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
Release historyRelease notifications |RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more aboutinstalling packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more aboutwheel file names.
Copy a direct link to the current filters
File details
Details for the fileunittest2-1.1.0.tar.gz.
File metadata
- Download URL:unittest2-1.1.0.tar.gz
- Upload date:
- Size: 81.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 22882a0e418c284e1f718a822b3b022944d53d2d908e1690b319a9d3eb2c0579 | |
| MD5 | f72dae5d44f091df36b6b513305ea000 | |
| BLAKE2b-256 | 7fc42b0e2d185d9d60772c10350d9853646832609d2f299a8300ab730f199db4 |
File details
Details for the fileunittest2-1.1.0-py2.py3-none-any.whl.
File metadata
- Download URL:unittest2-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 96.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8 | |
| MD5 | 4fb80726cfd1d8887a75e4a69b9da71a | |
| BLAKE2b-256 | 72207f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813 |