Skip to content

Instantly share code, notes, and snippets.

@sf105
Created December 27, 2022 18:33
Show Gist options
  • Save sf105/8909b3ee254ef098dc72a08ca1e8ca8c to your computer and use it in GitHub Desktop.
Save sf105/8909b3ee254ef098dc72a08ca1e8ca8c to your computer and use it in GitHub Desktop.
Code coverage for mutable variables
# 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