-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
additional unittest type equality methods #46830
Comments
unittest has many redundant APIs (eg. failIf and assertFalse) which can if x == y:
pass
else:
raise AssertionError(...) rather than if x != y:
raise AssertionError(...) |
My plan:
|
In a separate bug report, Steve Purcell indicated that he was taking |
I'm all for adding new APIs that provide new functionality (we have a I'm not for having several aliases for the same functionality; it maybe What's the bug# for Steve's proposal? |
See http://bugs.python.org/issue2249 for discussion. Personally, I prefer minimalism and would like the API thinned In Kent Beck's book on Test Driven Development, he complains that most Some of that may have been lost in a effort to model J-Unit or to If making big changes to the unittest API is on the table, it is worth |
Agreed that the various loader classes etc. are mostly a waste. The sad |
Hey, I'm open to anything. If I started writing unittest from scratch I think the design has held up pretty well, even if it's arguably not I don't intend to take unittest in any particular direction; truth be |
I think the current consensus is to start trimming the API in 3.1. We
Though I wonder how common that use case is. Not all new Pythoneers
I hope we can add more custom TestLoader/TestRunner subclasses for
And thanks for your continued involvement! I think the clue the |
Hey, I came to Python from Perl, Java *and* C++! I'm pretty sure the Adding more TestLoaders/TestRunners sounds like an excellent move. I'd I could certainly envisage the provision of convenience decorators that I was recently sent a fun paper describing a mechanism for transforming I'll be interested to see what people come up with, and to help a little |
Is there anything that can be done now about this issue? like renaming |
FYI - As a side note to this issue of removing the clutter of alternate This thread from last spring summarizes the types of things I'd like http://mail.python.org/pipermail/python-dev/2008-April/078716.html |
As an side-side-note, I find much more important to add some kind of |
@gpsmith: Way to go! @gpolo: Alas, test discovery is now a much harder problem because it |
Attaching a patch that adds Google's unittest.TestCase assertFooEqual() The following are added by this patch: + def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None): As I said in the dev summit, I'll get some stats on how often each of I did not include assertCommandSucceeds or assertCommandFails as those |
With all due respect, I find the presence of numerous type specific |
Some statistics from our large code base as to which of the assert These percentages are relative to the count of assertEqual(s) uses being assertListEqual 4.61% assertSequenceEqual is used by the List and Tuple equal functions so its I -did- add casing for the type to the main assertEqual method so it may |
Oh for reference, i left these out but they may interest people for assert_ 15% We don't currently have the auto type checking in assertEqual in our |
Well, that's my own aesthetical feeling. Others may disagree :) |
The naming pattern (assertListEqual, assertDictEqual, etc.) is pretty The names are also trivial to understand when reading tests that someone Finally, a simple refactoring of the code might be helpful where the |
Personally, I would prefer it if unittest got rid of all the various (crap, crap, crap. I was scrolling through the messages and my finger slid |
Just in case it can't be retrieved, here is Greg's text from msg84360: -------------------------------- assert_ 15% We don't currently have the auto type checking in assertEqual in our Again, my apologies. Skip |
I would love to use the time machine to kill the 'fail' variants as well (And don't worry, Skip, somebody already put that message back. You can |
2009/3/29 Guido van Rossum <report@bugs.python.org>:
Yes, actually this would be a great secondary use of 2to3's Besides, they're tests, so people would know if they're broken. :) |
Updated patch after sprinting on this with Michael Foord. TODO:
i'm working on the docs now. |
I absolutely do not want it to warn by default in 3.1. |
sounds good. This is done for 2.7. I will make sure it gets merged into 3.1 properly before closing. |
Do you mind if I rename all the double underscore methods that Greg's |
Do I mind? I *insist*! I thought put a note about that in the code |
Done in r71004. |
Bikeshedding a bit - the 'assertGreaterEqual' and 'assertLessEqual' Would it be possible to lengthen these specific names to the more Some really nice additions to the test module here! :) |
No, please. Get used to it. Maybe it helps if you realize the parallel |
Am I the only person who wishes all the assert* and fail* methods would Skip |
Why do you need the assert methods to go away in order to use assert |
Michael> Why do you need the assert methods to go away in order to use You don't, but use of assert statements seems a hell of a lot more Pythonic S |
Two problems:
|
Thanks Guido - the __ge__/le parallel does actually help me remember |
As far as I can tell for Python itself we never use -O while running unit
I've never had a problem with that. It yields a perfectly useful traceback, In any case, your test machinery will have to catch AssertionError |
No - you catch self.failureException rather than AssertionError directly. I use unittest precisely because of the rich failure information from |
Why is assertMultiLineEqual not the default assert method for basestring? Even for small strings the output is useful. |
assertMultiLineEqual might be reasonable as a default assertEqual for |
Fair point. :-) |
I'd like to add assertIs and assertNotIs. We have these at work and I would find them useful whilst writing tests |
Le samedi 04 avril 2009 à 15:06 +0000, Michael Foord a écrit :
Let's call it AssertIsNot (we type "x is not None", not "x not is |
I would *mmuch* prefer assertIsNot but it is not symmetrical with the |
Well, apparently assertIsNotNone() has been added, so it would be good |
I found while merging this to Py3k that dicts can't be used in |
Patch with assertIs and assertIsNot. Docs but nothing in NEWS as already Ok to apply? |
Patch for Py3k with fallback for comparing unsortable sequences in Removed the expected failure and added another test case to confirm that |
Seeing how a change in assertNotEqual unveiled a bug in OrderedDict, |
No, because the rich comparison docs explicitly state that the """There are no implied relationships among the comparison operators. (from http://docs.python.org/reference/datamodel.html#basic-customization) If someone is writing unit tests for comparison methods they should |
fyi - Your docs in unittest-assertis.diff mention the wrong method name The unittest-sameelements.diff patch looks good. |
Committed in revision 71263. Closing as there is nothing outstanding on |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: