On Thursday, January 16, 2020 at 3:51:10 PM UTC-5, Edward K. Ream wrote:
pytest --cov has revolutionized how I work.
>
...
> Once unit tests cover 100% of the code, *any* changes to the code should
> be valid, provided that:
>
> a) All unit tests still pass *and*
> b) All code remains covered.
>
When I began this reply, I thought I was going to describe a "cute trick"
for testing the Orange class. However, I soon realized that one unit test
illustrates *an essential technique* *for getting 100% coverage while unit
tests are failing.* As I write this, I have just realized what a big deal
this is.
The test_one_line_pet_peeves function contains a table of snippets. Modulo
some housekeeping, it is:
for contents in table: # table not shown. Some tests in the table fail.
contents, tokens, tree = self.make_data(contents, tag)
expected = self.blacken(contents)
results = self.beautify(contents, tag, tokens, tree)
if results != expected:
fails += 1
assert fails == 0, fails
*All the "one-line tests" run, even if some fail.*
It's also convenient to "pretend" that the test passes even when it
doesn't. That way the -x (fail fast) option doesn't bother us. So, for
now, the last line is:
assert fails == 13, fails
As I fix the unit test failures I'll decrease the error count.
*Summary*
When I started this reply, I thought I was going to describe just a cute
trick, namely using the call to self.blacken to get the expected results,
that is, the results that *black itself* delivers. Pretending that the test
passes is another cute trick.
Those are indeed useful tricks, but the *essential *trick is to *run all
the unit tests even while some are failing*. That's the *only* way to
ensure 100% coverage. That's a big, big deal, because without 100% coverage
we have *no way of knowing* whether code is dead or not!
Surely you can sense my excitement. This work flow is way, way, way better
than I ever thought possible.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/f52a7b64-aceb-4f5c-9d53-769a94b891d2%40googlegroups.com.