blueFast
blueFast

Reputation: 44431

Quick way to test that all symbols are defined for a module, without full unittest coverage

Let's say I have the following test script:

def b(): return 1

def a():
    b()
    c()

This module has a bug: c() is not defined/imported. But running this script will not fail, because a() is not called, and thus c() is not really needed. But as soon as a() is called, for example from another module, or whenever I modify the script to call a(), it will fail.

In this very simple case, it is easy to cover all possible execution paths with a unittest, which is the advisable thing to do. Unfortunately, my code is quite complex and I have no material time to prepare unit tests to cover all possible execution paths (which is a problem in itself, and I hope to solve in the future, but is currently out of the question)

Is there any way of checking that all symbols in all execution paths are defined for a specific module, without actually testing all execution paths?

Upvotes: 2

Views: 62

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599796

A linter like pylint or pyflakes will detect this sort of thing, via static analysis of the code.

They're very far from perfect though, as it is not possible in a dynamic language like Python to cover every possible path - without, as you say, actually running those paths. In my experience though they do catch a good number of errors.

Upvotes: 3

Related Questions