Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #110263
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Marking a subtest as an expected failure |
| Date | 2016-06-22 05:03 +1000 |
| Message-ID | <mailman.18.1466535815.11516.python-list@python.org> (permalink) |
| References | <5768faaa$0$2846$c3e8da3$76491128@news.astraweb.com> <858txyxt3a.fsf@benfinney.id.au> |
Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:
> def test_spam(self):
> for i in range(100):
> for j in range(100):
> with self.subtest(i=i, j=j):
> if (i, j) != (97, 83):
> self.assertEqual(spam(i, j), 999)
>
>
> but is there a nicer way to mark a specific subtest as an expected
> failure?
Expected failures and subtests are apparently not easily mixed using the
current API.
Digging into the ‘unittest.case’ module, the ‘expectedFailure’ decorator
does its job by setting the test case's ‘__unittest_expecting_failure__’
attribute to ‘True’.
Perhaps you can get the subtest object from the context manager, and
decide to set that magic attribute::
# …
with self.subtest(i=i, j=j) as subtest:
if (i, j) == (97, 83):
# The inhabitants of (97, 83) have always been trouble.
subtest.__unittest_expecting_failure__ = True
self.assertEqual(spam(i, j), 999)
That attribute is undocumented though, so I don't know whether to
consider that a nasty hack or a clever one. (Nor do I know whether it
works as I expect.)
You would be justified to report a bug that this interaction of useful
features should really be easier to access.
--
\ “Try adding “as long as you don't breach the terms of service – |
`\ according to our sole judgement” to the end of any cloud |
_o__) computing pitch.” —Simon Phipps, 2010-12-11 |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Marking a subtest as an expected failure Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-21 18:28 +1000 Re: Marking a subtest as an expected failure Ben Finney <ben+python@benfinney.id.au> - 2016-06-22 05:03 +1000
csiph-web