-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Change unittest's _SubTest to not sort its params when printing test failures #74849
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
Comments
Now that **kwargs are sorted, it would be better if the error given by a unittest subTest (as implemented in uniitest._case._SubTest) didn't sort the parameters when they're printed, but instead printed them out in order. This might be complicated by the ChainMap that's used as part of the implementation, but it should still be doable. For example, I have code that has: with self.subTest(hash=hash, cmp=cmp, frozen=frozen): But when it errors out, it produces:
It would be easier to check my code if the order the values was printed was the same as the order in the self.subTest() call. |
Correction: it's implemented in unittest.case._SubTest, specifically in _subDescription(). |
I think the question will be, when using multiple subTest (this is why using ChainMap I think), how to determine their order?: with self.subTest(c=i, b=i, a=i):
with self.subTest(b=i, c=50, a=60):
self.assertEqual(i, 2)
|
Good question. It looks like ChainMap does something I wouldn't expect: >>> for k, v in ChainMap({'a': 0, 'b': 1, 'c': 2}, {'b': 3, 'a': 4}).items():
... print(k, v)
...
b 1
a 0
c 2 Once we define what we'd like the output to look like, I'm sure it would be easy enough to get the order right. |
Additional note, the order will changed it random way in ChainMap, e.g.: >>> for k, v in ChainMap({'a': 0, 'b': 1, 'c': 2}, {'b': 3, 'a': 4}).items(): print(k, v)
...
a 0
c 2
b 1 -----restart---- >>> for k, v in ChainMap({'a': 0, 'b': 1, 'c': 2}, {'b': 3, 'a': 4}).items(): print(k, v)
...
b 1
c 2
a 0 |
Correct on the order changed with regular dicts. That's why I'm targeting this specifically for Python 3.7 and with **kwargs, where order is guaranteed. We might have to use a structure other than a ChainMap of dicts, like a ChainMap of OrderDicts. |
PR 2265 implements a private subclass of ChainMap that preserves ordering. |
Note that the order of parameters of nested subtests is from inner to outer. |
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: