Created
December 27, 2022 18:33
-
-
Save sf105/8909b3ee254ef098dc72a08ca1e8ca8c to your computer and use it in GitHub Desktop.
Code coverage for mutable variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've developed an unreasonable preference for helper functions over mutable | |
# variables. It turns out that there's one good reason why. This version of the | |
# code shows full code coverage. | |
topics = [] | |
if part_of_a_group: | |
topics = collected_works() | |
publish(topics) | |
# In this version of the code, the coverage tool shows that the "false" branch | |
# of the if statement is never taken. | |
def topics(part_of_a_group): | |
if part_of_a_group: | |
return collected_works() | |
return [] | |
publish(topics(part_of_a_group)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment