吃黑豆有什么好处| 尿检肌酐高是什么原因| 鼻子经常出血是什么原因| 七八年属什么生肖| 嗓子疼看什么科室| 滴虫性阴道炎用什么药好| 决明子有什么功效| 一岁宝宝发烧吃什么药| 冒昧是什么意思| 高考是什么| 灰指甲是什么样子| 神经内科和神经外科有什么区别| 舂米是什么意思| jo是什么意思| 什么鱼刺少好吃| 晚上睡觉多梦是什么原因| 藏红花不能和什么一起吃| 收敛是什么意思| 为什么会高血压| 鸡肉和什么相克| 犬子是什么意思| 什么的蚜虫| 汕头市花是什么花| 枸杞加什么泡水喝壮阳| 糖类抗原50是什么指标| 小河虾吃什么| 观察是什么意思| 毛囊是什么样子图片| 鹿五行属什么| 胎监不过关是什么原因| 卡波姆是什么| 子宫腺肌症是什么| 狗狗为什么喜欢舔人| 庸俗是什么意思| 为什么会有眼袋| 什么水解渴| 泌乳素偏高是什么原因| 冲任失调是什么意思| 海参和辽参有什么区别| 静候佳音是什么意思| 天津五行属什么| 甲炎是什么病| 除了火车什么车最长| 1比1是什么意思| 女人梦见下雪是什么征兆| 泰迪哼哼唧唧表示什么| 五点是什么时辰| 你的脚步流浪在天涯是什么歌曲| 什么叫窦性心律不齐| 为什么痛风就痛一只脚| fossil是什么意思| 发热出汗是什么原因| 肌酸激酶偏低是什么原因| 尿路感染吃什么| 本性难移是什么生肖| 万金油是什么意思| 左手中指痛什么预兆| 吃了发芽的土豆会有什么症状| 乌龟肠胃炎用什么药| 肺实变是什么意思| 花心大萝卜是什么意思| 勾践属什么生肖| 贝加台念什么| 什么是爱呢| 什么病不能吃西兰花| 什么是ppi| 排湿气最快的方法吃什么| 佛心是什么意思| 浅表性胃炎吃什么药好使| 什么叫房颤| 铁锈红配什么颜色好看| 半夏微凉是什么意思| 淋巴滤泡增生是什么意思| 鼻子发干是什么原因造成的| 棉花糖是什么做的| 老舍原名叫什么| 红醋是什么醋| 疼痛门诊看什么病| 脚出汗用什么药| 口腔溃疡吃什么消炎药| hf是什么| 尿蛋白定量是什么意思| hav是什么病毒| 带状疱疹有什么症状| 乌豆和黑豆有什么区别| 眼角发痒是什么原因| 冰释前嫌的释是什么意思| 孩子积食发烧吃什么药| 孕早期适合吃什么水果| 滴虫性阴道炎用什么药好| 出虚汗吃什么中成药| Q什么意思| 猴魁属于什么茶| 不寐病属于什么病症| 舌苔厚是什么原因引起的| 20岁长白头发是什么原因造成的| 胰岛素针头4mm和5mm有什么区别| 国印是什么意思| 常喝苦荞茶有什么好处| 骨髓纤维化是什么病| 手腕有痣代表什么| 臭氧是什么东西| 入木三分是什么意思| 大便不通吃什么药| 高危妊娠是什么意思啊| 过度紧张会有什么症状| graff是什么牌子| 提肛运动有什么好处| 肾b超能检查出什么| 贝贝是什么意思| 十滴水泡脚有什么好处| 夺目的什么| 合肥有什么好玩的地方| 什么地方| 商鞅姓什么| 燕窝什么人不适合吃| 病理是什么意思| 主任是什么意思| 功劳叶的别名叫什么| 尿潜血是什么病| 子宫腺肌症是什么原因引起的| 胃肠感冒可以吃什么水果| 足三里在什么位置图片| 智利说什么语言| 不举是什么原因造成的| 七个月宝宝可以吃什么辅食| neighborhood是什么意思| 雅戈尔男装什么档次| 牙痛用什么药| 口引念什么| 胸部痛是什么原因| 人流挂什么科| 授教什么意思| 卒中优先是什么意思| 扬长而去是什么意思| 花生死苗烂根用什么药| 失眠什么意思| 种植牙有什么风险和后遗症| 提前吃什么喝酒不醉| 七月二十八什么星座| 灯笼裤配什么鞋子好看| 不寐病是什么意思| 杨少华什么辈分| 脚麻看什么科室最好| 什么是养生| 澳大利亚属于什么洲| 喝白茶有什么好处| 舌头苦是什么原因| 人丝是什么面料| 眼白发青是什么原因| 猪肝配什么菜炒好吃| 酒后手麻什么原因| 脱式计算是什么意思| 什么颜色最吸热| 10月26是什么星座| 柠檬水喝了有什么好处| 2029年属什么生肖| 夏天晚饭吃什么比较好| 切除胆囊有什么影响| 一什么新闻| 宛字五行属什么| 阴虚湿热吃什么中成药| 六零年属什么生肖| 小孩子发烧吃什么药| 喝什么茶对肾好| od值是什么意思| 什么是换手率| 什么是放疗| 左眼上眼皮跳是什么预兆| 子息克乏是什么意思| 什么星座最花心| 济南为什么叫泉城| 东北大拉皮是什么做的| 猪八戒叫什么名字| 钱丢了预示着什么| 春捂秋冻指的是什么意思| 玫瑰红是什么颜色| 什么动物是站着睡觉的| 五毒为什么没有蜘蛛| 给老师送什么礼物好| 什么是偏光眼镜| 黄糖是什么糖| 梦见手机失而复得是什么意思| 厚颜无耻是什么意思| 五月是什么季节| 总是爱出汗是什么原因| 什么样的礼物| 女人脾胃虚弱吃什么好| 花生什么时候种| 二八佳人是什么意思| 为什么尿是黄的| 减肥吃什么零食| 肺五行属什么| 厚黑学的精髓是什么| 小孩老是咬手指甲是什么原因| left什么意思| 喝蜂蜜水对身体有什么好处| 夏季热是什么病| 阴道骚痒是什么原因| dmf是什么溶剂| 吃什么东西对胃好| 乳腺结节是什么引起的| 防晒衣的面料是什么| 新陈代谢是什么意思| 长期喝枸杞水有什么好处和坏处| 着重号是什么符号| 为什么刚吃完饭不能洗澡| louisvuitton什么牌子| 日本为什么侵略中国| 9月15号是什么星座| 猫的眼睛晚上为什么会发光| 红花是什么生肖| 情志是什么意思| 王俊凯什么星座| 书犹药也下一句是什么| 女性尿频繁是什么原因| 心脏早搏什么症状| 孩子a型血父母什么血型| 高湛为什么帮梅长苏| 11月10号是什么星座| cro公司是什么意思| 兰陵为什么改名枣庄| 天公作美是什么生肖| 什么的雄鸡| 梦见狗死了是什么预兆| 二网是什么意思| 热菜是什么梗| 更年期综合症吃什么药| 黄精什么功效| 理想主义是什么意思| 素什么意思| 漂白粉是什么| 龟头炎用什么药好| 心跳的快是什么原因| 1968属什么| 紫荆花代表什么生肖| 耵聍是什么| 议员在中国相当于什么| IC什么意思| 瓷娃娃什么意思| 83年属什么生肖| da是什么意思| 仙人掌有什么功效| 手掉皮是缺什么维生素| 西方属于五行属什么| 亲和力是什么意思| 浪子回头是什么意思| 焦虑症吃什么中成药能根治| 职业测试你适合什么工作| 颈椎病吃什么药好| 6.8什么星座| 脾虚吃什么水果| 32周做什么检查| 天秤座和什么星座最配| 势利眼是什么意思| 睾丸胀痛是什么原因| 珍惜当下是什么意思| 男的纹般若有什么寓意| 缺钙会出现什么症状| cvm是什么意思| 阑尾炎输液输什么药| 鸡精和味精有什么区别| 嘴角烂是什么原因| 棉纶是什么面料| 百度 Skip to main content

The new features in unittest backported to Python 2.4+.

Project description

unittest2 is a backport of the new features added to the unittest testing framework 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 replace import unittest with import unittest2.

unittest2 is maintained in a mercurial repository. The issue tracker is on google 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 with pip installing the wrong distribution, the Python 2.3 version of unittest2 can’t be hosted on PyPI:

There was a separate version of unittest2 for Python 3. This is no longer needed, but still exists on PyPI. This had the project name “unittest2py3k” but uses the same package name (“unittest2”):

Classes in unittest2 derive from the appropriate classes in unittest, so it should be possible to use the unittest2 test running infrastructure without having to switch all your tests to using unittest2 immediately. Similarly you can use the new assert methods on unittest2.TestCase with the standard unittest test running infrastructure. Not all of the new features in unittest2 will work with the standard unittest test loaders, runners result objects however.

In general for documentation on unittest2 see the current latest documented of CPython:

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 methods for comparing specific types

  • assertRaises as context manager, with access to the exception afterwards

  • test discovery and new command line options (including failfast and better handling of ctrl-C during test runs)

  • class and module level fixtures: setUpClass, tearDownClass, setUpModule, tearDownModule

  • test skipping and expected failures

  • new delta keyword argument to assertAlmostEqual for more useful comparison and for comparing non-numeric objects (like datetimes)

  • load_tests protocol for loading tests from modules or packages

  • startTestRun and stopTestRun methods on TestResult

  • various other API improvements and fixes

Until I write proper documentation, the best information on all the new features is the development version of the Python documentation for Python 2.7:

Look for notes about features added or changed in Python 2.7.

Differences

Differences between unittest2 and unittest in Python 2.7:

assertItemsEqual does not silence Py3k warnings as this uses warnings.catch_warnings() which is new in Python 2.6 (and is used as a context manager which would be a pain to make work with Python 2.4).

TestCase.longMessage defaults to True because it is better. It defaults to False in Python 2.7 for backwards compatibility reasons.

python -m package doesn’t work in versions of Python before Python 2.7. The command line features of unittest2 are provided by a unit2 (and unit2.py) script instead.

unittest2 includes a very basic setuptools compatible test collector. Specify test_suite = 'unittest2.collector' in your setup.py. This starts test discovery with the default parameters from the directory containing setup.py, so it 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 was documented as being empty and subclasses shouldn’t need to call it. This would make the change backwards incompatible and needs thinking about.

Issues

A TestResult object with unexpected successes returns True for result.wasSuccessful(). Difficult to know if this is the correct behaviour or not.

If a dotted path name is used for test discovery then a globally installed module/package will still be used in preference of one in the current directory. When doing discovery from a dotted path name we could check for this specific case.

The removeHandler 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 and traceback objects. As the issue is rare I am leaving it unfixed in unittest2.

There are several places in unittest2 (and unittest) that call str(...) on exceptions to get the exception message. This can fail if the exception was created with non-ascii unicode. This is rare and I won’t address it unless it is actually reported as a problem for someone.

A comparison of text or long sequences (using assertSequenceEqual or assertMultiLineEqual etc) can take a long time to generate diffs for failure messages. These methods use prettyprint and difflib.

pip install -e . on Python3.2 in the unittest2 source will fail unless setuptools > 0.6.24 is already installed. This is a combination of needing a newer setuptools (to avoid the use of execfile) and setup_requires falling back to easy_install that doesn’t know how to upgrade setuptools just-in-time that prevents it being fixed in unittest2.

CHANGELOG

2025-08-06 - 1.1.0

  • Issue #15836: assertRaises(), assertRaisesRegex(), assertWarns() and assertWarnsRegex() assertments now check the type of the first argument to prevent possible user error. Based on patch by Daniel Wagner-Hall.

  • Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() and assertWarnsRegex() checks now emits a deprecation warning when callable is None or keyword arguments except msg is passed in the context manager mode.

  • Issue #22903: The fake test case created by unittest.loader when it fails importing a test module is now picklable.

2025-08-06 - 1.0.1

  • Unittest2 issue #94: Need at least 1.4 of six.

2025-08-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 stopped when 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 entrypoint scripts to just entrypoint scripts to reduce the possibility of similar oversights in future.

2014/10/31 - 0.7.0

This release contains backports from cPython 3.5 of all (I think) commits since 2010, as of today.

2014/10/28 - 0.6.0

Many thanks to Mark Roddy and Ezio Melotti who contributed substantially to this release.

  • Changed supported Python versions to start at 2.6, and include all released 3.x and pypy. (Robert Collins)

  • Invoking unit2 without args starts test discovery

  • Added TestCase.assertWarns and TestCase.assertWarnsRegexp context managers

  • Fix Python issue 9926. TestSuite subclasses that override __call__ are called correctly.

  • Removed unused maxDiff parameter from TestCase.assertSequenceEqual.

  • DeprecationWarning for unsupported result objects (missing addSkip method) became RuntimeWarning.

  • Addition of TestCase.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 scripts anyway.)

2010/07/11 - 0.5.0

Addition of a setuptools compatible test collector (very basic). Specify test_suite = 'unittest2.collector' in your setup.py.

TestSuite.debug() and TestCase.debug() now execute cleanup functions and class and module level setups and teardowns.

No longer monkey-patch os.path.relpath for Python 2.4 / 2.5 so that projects don’t accidentally depend on our patching. Contributed by Konrad Delong.

Added a Python version specific unit2 entrypoint. This will, for example, create a unit2-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 for unit2 discover -h.

SkipTest in unittest.TestCase.setUpClass or setUpModule is now reported as a skip rather than an error.

Excessively large diffs due to TestCase.assertSequenceEqual are no longer included in failure reports. (Controlled by TestCase.maxDiff.)

Matching files during test discovery is done in TestLoader._match_path. This method can be overriden in subclasses to, for example, match on the full file path 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 are silenced 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 the module is globally installed and the user is expecting to run tests against a development version in a different location) then discovery halts with an ImportError and the problem is reported.

Added docstrings to assertRegexpMatches and assertNotRegexpMatches.

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 of removeHandler for removing the control-C handler.

delta keyword argument for assertAlmostEqual and assertNotAlmostEqual.

Addition of -b command line option (and TestResult.buffer) for buffering stdout / stderr during test runs.

Addition of TestCase.assertNotRegexpMatches.

Allow test discovery using dotted module names instead of a path.

All imports requiring the signal module are now optional, for compatiblity with IronPython (or other platforms without this module).

Tests fixed to be compatible with nosetest.

2010/03/26 - 0.3.0

assertSameElements removed and assertItemsEqual added; assert that sequences contain the same elements.

Addition of -f/–failfast command line option, stopping test run on first failure or error.

Addition of -c/–catch command line option for better control-C handling during test runs.

Added BaseTestSuite, for use by frameworks that don’t want to support shared class and module fixtures.

Skipped test methods no longer have setUp and tearDown called around them.

Faulty load_tests functions no longer halt test discovery.

Using non-strings for failure messages now works.

Potential for UnicodeDecodeError 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 in reported stacktraces.

2010/03/06 - 0.2.0

The TextTestRunner 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 old TestResult objects. New tests can now be run with nosetests (with a DeprecationWarning for TestResult objects without methods to support skipping etc).

0.1

Initial release.

TODO

  • Document SkipTest, BaseTestSuite`

Release process

1. Make sure there is an entry in the Changelog in this document. 1. Update __version__ in unittest2/__init__.py 1. 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. Run make release to build an sdist and wheel and upload to pypi.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unittest2-1.1.0.tar.gz (81.4 kB view details)

Uploaded Source

Built Distribution

unittest2-1.1.0-py2.py3-none-any.whl (96.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file unittest2-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

Hashes for unittest2-1.1.0.tar.gz
Algorithm Hash digest
SHA256 22882a0e418c284e1f718a822b3b022944d53d2d908e1690b319a9d3eb2c0579
MD5 f72dae5d44f091df36b6b513305ea000
BLAKE2b-256 7fc42b0e2d185d9d60772c10350d9853646832609d2f299a8300ab730f199db4

See more details on using hashes here.

File details

Details for the file unittest2-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for unittest2-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8
MD5 4fb80726cfd1d8887a75e4a69b9da71a
BLAKE2b-256 72207f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page
胃不好吃什么水果 扁平苔藓有什么症状 一什么雨伞 风寒感冒流鼻涕吃什么药 皮肤瘙痒用什么药膏
什么叫做质量 淋巴结节吃什么药最好 抖m是什么 胃不舒服恶心想吐吃什么药 急性结肠炎什么症状
风景旧曾谙是什么意思 今天穿什么衣服合适 体重用什么单位 练瑜伽有什么好处 山药和什么不能一起吃
末梢血是什么意思 肝炎吃什么药好 神经损伤是什么症状 孕检无创是检查什么的 白细胞少会引起什么病
蜻蜓为什么点水hcv9jop2ns9r.cn 醪糟发酸是什么原因hcv8jop7ns6r.cn 什么原因导致荨麻疹inbungee.com 小孩肠系膜淋巴结炎吃什么药fenrenren.com 性功能下降是什么原因hcv8jop4ns4r.cn
精索静脉曲张是什么原因导致的hcv9jop1ns7r.cn 肝主筋的筋是指什么fenrenren.com 白虎痣是什么意思hcv7jop5ns3r.cn 至多是什么意思hcv8jop0ns1r.cn 大疱性皮肤病是什么病hcv8jop4ns2r.cn
宝贝是什么意思imcecn.com 窦炎是什么意思hcv8jop8ns1r.cn 又热又冷是什么原因gysmod.com 白细胞阴性什么意思hcv7jop6ns7r.cn 胆囊挂什么科hcv9jop3ns8r.cn
梦到怀孕了是什么预兆hcv8jop8ns6r.cn 撤退性出血是什么意思hcv8jop0ns2r.cn 什么是食品添加剂hcv7jop6ns1r.cn 风疹是什么样子图片hcv9jop7ns4r.cn 脸上起红疙瘩是什么原因hcv8jop5ns4r.cn
百度