4 Changes and improvements to testtools_, grouped by release.
12 * ``MatchesAll`` now takes an ``first_only`` keyword argument that changes how
13 mismatches are displayed. If you were previously passing matchers to
14 ``MatchesAll`` with keyword arguments, then this change might affect your
15 test results. (Jonathan Lange)
20 * Actually hide all of the testtools stack for assertion failures. The
21 previous release promised clean stack, but now we actually provide it.
22 (Jonathan Lange, #854769)
24 * Failed equality assertions now line up. (Jonathan Lange, #879339)
26 * ``MatchesAll`` and ``MatchesListwise`` both take a ``first_only`` keyword
27 argument. If True, they will report only on the first mismatch they find,
28 and not continue looking for other possible mismatches.
33 * ``DirContains`` matches the contents of a directory.
34 (Jonathan Lange, James Westby)
36 * ``DirExists`` matches if a directory exists.
37 (Jonathan Lange, James Westby)
39 * ``FileContains`` matches the contents of a file.
40 (Jonathan Lange, James Westby)
42 * ``FileExists`` matches if a file exists.
43 (Jonathan Lange, James Westby)
45 * ``HasPermissions`` matches the permissions of a file. (Jonathan Lange)
47 * ``MatchesPredicate`` matches if a predicate is true. (Jonathan Lange)
49 * ``PathExists`` matches if a path exists. (Jonathan Lange, James Westby)
51 * ``SamePath`` matches if two paths are the same. (Jonathan Lange)
53 * ``TarballContains`` matches the contents of a tarball. (Jonathan Lange)
59 This is a very big release. We've made huge improvements on three fronts:
60 1. Test failures are way nicer and easier to read
61 2. Matchers and ``assertThat`` are much more convenient to use
62 3. Correct handling of extended unicode characters
64 We've trimmed off the fat from the stack trace you get when tests fail, we've
65 cut out the bits of error messages that just didn't help, we've made it easier
66 to annotate mismatch failures, to compare complex objects and to match raised
69 Testing code was never this fun.
74 * ``AfterPreproccessing`` renamed to ``AfterPreprocessing``, which is a more
75 correct spelling. Old name preserved for backwards compatibility, but is
76 now deprecated. Please stop using it.
77 (Jonathan Lange, #813460)
79 * ``assertThat`` raises ``MismatchError`` instead of
80 ``TestCase.failureException``. ``MismatchError`` is a subclass of
81 ``AssertionError``, so in most cases this change will not matter. However,
82 if ``self.failureException`` has been set to a non-default value, then
83 mismatches will become test errors rather than test failures.
85 * ``gather_details`` takes two dicts, rather than two detailed objects.
86 (Jonathan Lange, #801027)
88 * ``MatchesRegex`` mismatch now says "<value> does not match /<regex>/" rather
89 than "<regex> did not match <value>". The regular expression contains fewer
90 backslashes too. (Jonathan Lange, #818079)
92 * Tests that run with ``AsynchronousDeferredRunTest`` now have the ``reactor``
93 attribute set to the running reactor. (Jonathan Lange, #720749)
98 * All public matchers are now in ``testtools.matchers.__all__``.
99 (Jonathan Lange, #784859)
101 * ``assertThat`` can actually display mismatches and matchers that contain
102 extended unicode characters. (Jonathan Lange, Martin [gz], #804127)
104 * ``assertThat`` output is much less verbose, displaying only what the mismatch
105 tells us to display. Old-style verbose output can be had by passing
106 ``verbose=True`` to assertThat. (Jonathan Lange, #675323, #593190)
108 * ``assertThat`` accepts a message which will be used to annotate the matcher.
109 This can be given as a third parameter or as a keyword parameter.
112 * Automated the Launchpad part of the release process.
113 (Jonathan Lange, #623486)
115 * Correctly display non-ASCII unicode output on terminals that claim to have a
116 unicode encoding. (Martin [gz], #804122)
118 * ``DocTestMatches`` correctly handles unicode output from examples, rather
119 than raising an error. (Martin [gz], #764170)
121 * ``ErrorHolder`` and ``PlaceHolder`` added to docs. (Jonathan Lange, #816597)
123 * ``ExpectedException`` now matches any exception of the given type by
124 default, and also allows specifying a ``Matcher`` rather than a mere regular
125 expression. (Jonathan Lange, #791889)
127 * ``FixtureSuite`` added, allows test suites to run with a given fixture.
130 * Hide testtools's own stack frames when displaying tracebacks, making it
131 easier for test authors to focus on their errors.
132 (Jonathan Lange, Martin [gz], #788974)
134 * Less boilerplate displayed in test failures and errors.
135 (Jonathan Lange, #660852)
137 * ``MatchesException`` now allows you to match exceptions against any matcher,
138 rather than just regular expressions. (Jonathan Lange, #791889)
140 * ``MatchesException`` now permits a tuple of types rather than a single type
141 (when using the type matching mode). (Robert Collins)
143 * ``MatchesStructure.byEquality`` added to make the common case of matching
144 many attributes by equality much easier. ``MatchesStructure.byMatcher``
145 added in case folk want to match by things other than equality.
148 * New convenience assertions, ``assertIsNone`` and ``assertIsNotNone``.
153 * ``AllMatch`` matches many values against a single matcher.
154 (Jonathan Lange, #615108)
156 * ``Contains``. (Robert Collins)
158 * ``GreaterThan``. (Christian Kampka)
160 * New helper, ``safe_hasattr`` added. (Jonathan Lange)
162 * ``reraise`` added to ``testtools.compat``. (Jonathan Lange)
168 This release brings consistent use of super for better compatibility with
169 multiple inheritance, fixed Python3 support, improvements in fixture and mather
170 outputs and a compat helper for testing libraries that deal with bytestrings.
175 * ``TestCase`` now uses super to call base ``unittest.TestCase`` constructor,
176 ``setUp`` and ``tearDown``. (Tim Cole, #771508)
178 * If, when calling ``useFixture`` an error occurs during fixture set up, we
179 still attempt to gather details from the fixture. (Gavin Panella)
185 * Additional compat helper for ``BytesIO`` for libraries that build on
186 testtools and are working on Python 3 porting. (Robert Collins)
188 * Corrected documentation for ``MatchesStructure`` in the test authors
189 document. (Jonathan Lange)
191 * ``LessThan`` error message now says something that is logically correct.
192 (Gavin Panella, #762008)
194 * Multiple details from a single fixture are now kept separate, rather than
195 being mooshed together. (Gavin Panella, #788182)
197 * Python 3 support now back in action. (Martin [gz], #688729)
199 * ``try_import`` and ``try_imports`` have a callback that is called whenever
200 they fail to import a module. (Martin Pool)
206 The last release of testtools could not be easy_installed. This is considered
207 severe enough for a re-release.
212 * Include ``doc/`` in the source distribution, making testtools installable
213 from PyPI again (Tres Seaver, #757439)
219 Many, many new matchers, vastly expanded documentation, stacks of bug fixes,
220 better unittest2 integration. If you've ever wanted to try out testtools but
221 been afraid to do so, this is the release to try.
227 * The timestamps generated by ``TestResult`` objects when no timing data has
228 been received are now datetime-with-timezone, which allows them to be
229 sensibly serialised and transported. (Robert Collins, #692297)
234 * ``AnnotatedMismatch`` now correctly returns details.
235 (Jonathan Lange, #724691)
237 * distutils integration for the testtools test runner. Can now use it for
238 'python setup.py test'. (Christian Kampka, #693773)
240 * ``EndsWith`` and ``KeysEqual`` now in testtools.matchers.__all__.
241 (Jonathan Lange, #692158)
243 * ``MatchesException`` extended to support a regular expression check against
244 the str() of a raised exception. (Jonathan Lange)
246 * ``MultiTestResult`` now forwards the ``time`` API. (Robert Collins, #692294)
248 * ``MultiTestResult`` now documented in the manual. (Jonathan Lange, #661116)
250 * New content helpers ``content_from_file``, ``content_from_stream`` and
251 ``attach_file`` make it easier to attach file-like objects to a
252 test. (Jonathan Lange, Robert Collins, #694126)
254 * New ``ExpectedException`` context manager to help write tests against things
255 that are expected to raise exceptions. (Aaron Bentley)
259 * ``MatchesListwise`` matches an iterable of matchers against an iterable
260 of values. (Michael Hudson-Doyle)
262 * ``MatchesRegex`` matches a string against a regular expression.
263 (Michael Hudson-Doyle)
265 * ``MatchesStructure`` matches attributes of an object against given
266 matchers. (Michael Hudson-Doyle)
268 * ``AfterPreproccessing`` matches values against a matcher after passing them
269 through a callable. (Michael Hudson-Doyle)
271 * ``MatchesSetwise`` matches an iterable of matchers against an iterable of
272 values, without regard to order. (Michael Hudson-Doyle)
274 * ``setup.py`` can now build a snapshot when Bazaar is installed but the tree
275 is not a Bazaar tree. (Jelmer Vernooij)
277 * Support for running tests using distutils (Christian Kampka, #726539)
279 * Vastly improved and extended documentation. (Jonathan Lange)
281 * Use unittest2 exception classes if available. (Jelmer Vernooij)
287 In this release we bring some very interesting improvements:
289 * new matchers for exceptions, sets, lists, dicts and more.
291 * experimental (works but the contract isn't supported) twisted reactor
294 * The built in runner can now list tests and filter tests (the -l and
295 --load-list options).
300 * addUnexpectedSuccess is translated to addFailure for test results that don't
301 know about addUnexpectedSuccess. Further, it fails the entire result for
302 all testtools TestResults (i.e. wasSuccessful() returns False after
303 addUnexpectedSuccess has been called). Note that when using a delegating
304 result such as ThreadsafeForwardingResult, MultiTestResult or
305 ExtendedToOriginalDecorator then the behaviour of addUnexpectedSuccess is
306 determined by the delegated to result(s).
307 (Jonathan Lange, Robert Collins, #654474, #683332)
309 * startTestRun will reset any errors on the result. That is, wasSuccessful()
310 will always return True immediately after startTestRun() is called. This
311 only applies to delegated test results (ThreadsafeForwardingResult,
312 MultiTestResult and ExtendedToOriginalDecorator) if the delegated to result
313 is a testtools test result - we cannot reliably reset the state of unknown
314 test result class instances. (Jonathan Lange, Robert Collins, #683332)
316 * Responsibility for running test cleanups has been moved to ``RunTest``.
317 This change does not affect public APIs and can be safely ignored by test
318 authors. (Jonathan Lange, #662647)
325 * ``EndsWith`` which complements the existing ``StartsWith`` matcher.
326 (Jonathan Lange, #669165)
328 * ``MatchesException`` matches an exception class and parameters. (Robert
331 * ``KeysEqual`` matches a dictionary with particular keys. (Jonathan Lange)
333 * ``assertIsInstance`` supports a custom error message to be supplied, which
334 is necessary when using ``assertDictEqual`` on Python 2.7 with a
335 ``testtools.TestCase`` base class. (Jelmer Vernooij)
337 * Experimental support for running tests that return Deferreds.
338 (Jonathan Lange, Martin [gz])
340 * Provide a per-test decorator, run_test_with, to specify which RunTest
341 object to use for a given test. (Jonathan Lange, #657780)
343 * Fix the runTest parameter of TestCase to actually work, rather than raising
344 a TypeError. (Jonathan Lange, #657760)
346 * Non-release snapshots of testtools will now work with buildout.
347 (Jonathan Lange, #613734)
349 * Malformed SyntaxErrors no longer blow up the test suite. (Martin [gz])
351 * ``MismatchesAll.describe`` no longer appends a trailing newline.
352 (Michael Hudson-Doyle, #686790)
354 * New helpers for conditionally importing modules, ``try_import`` and
355 ``try_imports``. (Jonathan Lange)
357 * ``Raises`` added to the ``testtools.matchers`` module - matches if the
358 supplied callable raises, and delegates to an optional matcher for validation
359 of the exception. (Robert Collins)
361 * ``raises`` added to the ``testtools.matchers`` module - matches if the
362 supplied callable raises and delegates to ``MatchesException`` to validate
363 the exception. (Jonathan Lange)
365 * Tests will now pass on Python 2.6.4 : an ``Exception`` change made only in
366 2.6.4 and reverted in Python 2.6.5 was causing test failures on that version.
367 (Martin [gz], #689858).
369 * ``testtools.TestCase.useFixture`` has been added to glue with fixtures nicely.
372 * ``testtools.run`` now supports ``-l`` to list tests rather than executing
373 them. This is useful for integration with external test analysis/processing
374 tools like subunit and testrepository. (Robert Collins)
376 * ``testtools.run`` now supports ``--load-list``, which takes a file containing
377 test ids, one per line, and intersects those ids with the tests found. This
378 allows fine grained control of what tests are run even when the tests cannot
379 be named as objects to import (e.g. due to test parameterisation via
380 testscenarios). (Robert Collins)
382 * Update documentation to say how to use testtools.run() on Python 2.4.
383 (Jonathan Lange, #501174)
385 * ``text_content`` conveniently converts a Python string to a Content object.
386 (Jonathan Lange, James Westby)
393 Lots of little cleanups in this release; many small improvements to make your
394 testing life more pleasant.
399 * Cleanups can raise ``testtools.MultipleExceptions`` if they have multiple
400 exceptions to report. For instance, a cleanup which is itself responsible for
401 running several different internal cleanup routines might use this.
403 * Code duplication between assertEqual and the matcher Equals has been removed.
405 * In normal circumstances, a TestCase will no longer share details with clones
406 of itself. (Andrew Bennetts, bug #637725)
408 * Less exception object cycles are generated (reduces peak memory use between
409 garbage collection). (Martin [gz])
411 * New matchers 'DoesNotStartWith' and 'StartsWith' contributed by Canonical
412 from the Launchpad project. Written by James Westby.
414 * Timestamps as produced by subunit protocol clients are now forwarded in the
415 ThreadsafeForwardingResult so correct test durations can be reported.
416 (Martin [gz], Robert Collins, #625594)
418 * With unittest from Python 2.7 skipped tests will now show only the reason
419 rather than a serialisation of all details. (Martin [gz], #625583)
421 * The testtools release process is now a little better documented and a little
422 smoother. (Jonathan Lange, #623483, #623487)
428 Nothing major in this release, just enough small bits and pieces to make it
429 useful enough to upgrade to.
431 In particular, a serious bug in assertThat() has been fixed, it's easier to
432 write Matchers, there's a TestCase.patch() method for those inevitable monkey
433 patches and TestCase.assertEqual gives slightly nicer errors.
438 * 'TestCase.assertEqual' now formats errors a little more nicely, in the
441 * Added `PlaceHolder` and `ErrorHolder`, TestCase-like objects that can be
442 used to add results to a `TestResult`.
444 * 'Mismatch' now takes optional description and details parameters, so
445 custom Matchers aren't compelled to make their own subclass.
447 * jml added a built-in UTF8_TEXT ContentType to make it slightly easier to
448 add details to test results. See bug #520044.
450 * Fix a bug in our built-in matchers where assertThat would blow up if any
451 of them failed. All built-in mismatch objects now provide get_details().
453 * New 'Is' matcher, which lets you assert that a thing is identical to
456 * New 'LessThan' matcher which lets you assert that a thing is less than
459 * TestCase now has a 'patch()' method to make it easier to monkey-patching
460 objects in tests. See the manual for more information. Fixes bug #310770.
462 * MultiTestResult methods now pass back return values from the results it
468 This release fixes some obscure traceback formatting issues that probably
469 weren't affecting you but were certainly breaking our own test suite.
474 * Jamu Kakar has updated classes in testtools.matchers and testtools.runtest
475 to be new-style classes, fixing bug #611273.
480 * Martin[gz] fixed traceback handling to handle cases where extract_tb returns
481 a source line of None. Fixes bug #611307.
483 * Martin[gz] fixed an unicode issue that was causing the tests to fail,
486 * testtools now handles string exceptions (although why would you want to use
487 them?) and formats their tracebacks correctly. Thanks to Martin[gz] for
493 This release overhauls the traceback formatting layer to deal with Python 2
494 line numbers and traceback objects often being local user encoded strings
495 rather than unicode objects. Test discovery has also been added and Python 3.1
496 is also supported. Finally, the Mismatch protocol has been extended to let
497 Matchers collaborate with tests in supplying detailed data about failures.
502 * testtools.utils has been renamed to testtools.compat. Importing
503 testtools.utils will now generate a deprecation warning.
508 * Add machinery for Python 2 to create unicode tracebacks like those used by
509 Python 3. This means testtools no longer throws on encountering non-ascii
510 filenames, source lines, or exception strings when displaying test results.
511 Largely contributed by Martin[gz] with some tweaks from Robert Collins.
513 * James Westby has supplied test discovery support using the Python 2.7
514 TestRunner in testtools.run. This requires the 'discover' module. This
517 * Python 3.1 is now supported, thanks to Martin[gz] for a partial patch.
518 This fixes bug #592375.
520 * TestCase.addCleanup has had its docstring corrected about when cleanups run.
522 * TestCase.skip is now deprecated in favour of TestCase.skipTest, which is the
523 Python2.7 spelling for skip. This closes bug #560436.
525 * Tests work on IronPython patch from Martin[gz] applied.
527 * Thanks to a patch from James Westby testtools.matchers.Mismatch can now
528 supply a get_details method, which assertThat will query to provide
529 additional attachments. This can be used to provide additional detail
530 about the mismatch that doesn't suite being included in describe(). For
531 instance, if the match process was complex, a log of the process could be
532 included, permitting debugging.
534 * testtools.testresults.real._StringException will now answer __str__ if its
535 value is unicode by encoding with UTF8, and vice versa to answer __unicode__.
536 This permits subunit decoded exceptions to contain unicode and still format
542 More matchers, Python 2.4 support, faster test cloning by switching to copy
543 rather than deepcopy and better output when exceptions occur in cleanups are
544 the defining characteristics of this release.
549 * New matcher "Annotate" that adds a simple string message to another matcher,
550 much like the option 'message' parameter to standard library assertFoo
553 * New matchers "Not" and "MatchesAll". "Not" will invert another matcher, and
554 "MatchesAll" that needs a successful match for all of its arguments.
556 * On Python 2.4, where types.FunctionType cannot be deepcopied, testtools will
557 now monkeypatch copy._deepcopy_dispatch using the same trivial patch that
558 added such support to Python 2.5. The monkey patch is triggered by the
559 absence of FunctionType from the dispatch dict rather than a version check.
562 * On windows the test 'test_now_datetime_now' should now work reliably.
564 * TestCase.getUniqueInteger and TestCase.getUniqueString now have docstrings.
566 * TestCase.getUniqueString now takes an optional prefix parameter, so you can
567 now use it in circumstances that forbid strings with '.'s, and such like.
569 * testtools.testcase.clone_test_with_new_id now uses copy.copy, rather than
570 copy.deepcopy. Tests that need a deeper copy should use the copy protocol to
571 control how they are copied. Bug #498869.
573 * The backtrace test result output tests should now pass on windows and other
574 systems where os.sep is not '/'.
576 * When a cleanUp or tearDown exception occurs, it is now accumulated as a new
577 traceback in the test details, rather than as a separate call to addError /
578 addException. This makes testtools work better with most TestResult objects
579 and fixes bug #335816.
585 Python 3 support, more matchers and better consistency with Python 2.7 --
586 you'd think that would be enough for a point release. Well, we here on the
587 testtools project think that you deserve more.
589 We've added a hook so that user code can be called just-in-time whenever there
590 is an exception, and we've also factored out the "run" logic of test cases so
591 that new outcomes can be added without fiddling with the actual flow of logic.
593 It might sound like small potatoes, but it's changes like these that will
594 bring about the end of test frameworks.
600 * A failure in setUp and tearDown now report as failures not as errors.
602 * Cleanups now run after tearDown to be consistent with Python 2.7's cleanup
605 * ExtendedToOriginalDecorator now passes unrecognised attributes through
606 to the decorated result object, permitting other extensions to the
607 TestCase -> TestResult protocol to work.
609 * It is now possible to trigger code just-in-time after an exception causes
610 a test outcome such as failure or skip. See the testtools MANUAL or
611 ``pydoc testtools.TestCase.addOnException``. (bug #469092)
613 * New matcher Equals which performs a simple equality test.
615 * New matcher MatchesAny which looks for a match of any of its arguments.
617 * TestCase no longer breaks if a TestSkipped exception is raised with no
620 * TestCase.run now clones test cases before they are run and runs the clone.
621 This reduces memory footprint in large test runs - state accumulated on
622 test objects during their setup and execution gets freed when test case
623 has finished running unless the TestResult object keeps a reference.
624 NOTE: As test cloning uses deepcopy, this can potentially interfere if
625 a test suite has shared state (such as the testscenarios or testresources
626 projects use). Use the __deepcopy__ hook to control the copying of such
627 objects so that the shared references stay shared.
629 * Testtools now accepts contributions without copyright assignment under some
630 circumstances. See HACKING for details.
632 * Testtools now provides a convenient way to run a test suite using the
633 testtools result object: python -m testtools.run testspec [testspec...].
635 * Testtools now works on Python 3, thanks to Benjamin Peterson.
637 * Test execution now uses a separate class, testtools.RunTest to run single
638 tests. This can be customised and extended in a more consistent fashion than
639 the previous run method idiom. See pydoc for more information.
641 * The test doubles that testtools itself uses are now available as part of
642 the testtools API in testtols.testresult.doubles.
644 * TracebackContent now sets utf8 as the charset encoding, rather than not
645 setting one and encoding with the default encoder.
647 * With python2.7 testtools.TestSkipped will be the unittest.case.SkipTest
648 exception class making skips compatible with code that manually raises the
649 standard library exception. (bug #490109)
654 * TestCase.getUniqueInteger is now implemented using itertools.count. Thanks
655 to Benjamin Peterson for the patch. (bug #490111)
661 The new matcher API introduced in 0.9.0 had a small flaw where the matchee
662 would be evaluated twice to get a description of the mismatch. This could lead
663 to bugs if the act of matching caused side effects to occur in the matchee.
664 Since having such side effects isn't desirable, we have changed the API now
665 before it has become widespread.
670 * Matcher API changed to avoid evaluating matchee twice. Please consult
671 the API documentation.
673 * TestCase.getUniqueString now uses the test id, not the test method name,
674 which works nicer with parameterised tests.
679 * Python2.4 is now supported again.
685 This release of testtools is perhaps the most interesting and exciting one
686 it's ever had. We've continued in bringing together the best practices of unit
687 testing from across a raft of different Python projects, but we've also
688 extended our mission to incorporating unit testing concepts from other
689 languages and from our own research, led by Robert Collins.
691 We now support skipping and expected failures. We'll make sure that you
692 up-call setUp and tearDown, avoiding unexpected testing weirdnesses. We're
693 now compatible with Python 2.5, 2.6 and 2.7 unittest library.
695 All in all, if you are serious about unit testing and want to get the best
696 thinking from the whole Python community, you should get this release.
701 * A new TestResult API has been added for attaching details to test outcomes.
702 This API is currently experimental, but is being prepared with the intent
703 of becoming an upstream Python API. For more details see pydoc
704 testtools.TestResult and the TestCase addDetail / getDetails methods.
706 * assertThat has been added to TestCase. This new assertion supports
707 a hamcrest-inspired matching protocol. See pydoc testtools.Matcher for
708 details about writing matchers, and testtools.matchers for the included
709 matchers. See http://code.google.com/p/hamcrest/.
711 * Compatible with Python 2.6 and Python 2.7
713 * Failing to upcall in setUp or tearDown will now cause a test failure.
714 While the base methods do nothing, failing to upcall is usually a problem
715 in deeper hierarchies, and checking that the root method is called is a
716 simple way to catch this common bug.
718 * New TestResult decorator ExtendedToOriginalDecorator which handles
719 downgrading extended API calls like addSkip to older result objects that
720 do not support them. This is used internally to make testtools simpler but
721 can also be used to simplify other code built on or for use with testtools.
723 * New TextTestResult supporting the extended APIs that testtools provides.
725 * Nose will no longer find 'runTest' tests in classes derived from
726 testtools.testcase.TestCase (bug #312257).
728 * Supports the Python 2.7/3.1 addUnexpectedSuccess and addExpectedFailure
729 TestResult methods, with a support function 'knownFailure' to let tests
730 trigger these outcomes.
732 * When using the skip feature with TestResult objects that do not support it
733 a test success will now be reported. Previously an error was reported but
734 production experience has shown that this is too disruptive for projects that
735 are using skips: they cannot get a clean run on down-level result objects.
738 .. _testtools: http://pypi.python.org/pypi/testtools