Skip to content

Instantly share code, notes, and snippets.

@FGtatsuro
Created July 7, 2018 08:31
Show Gist options
  • Save FGtatsuro/53348aba74d3ee368821328e5d97138a to your computer and use it in GitHub Desktop.
Save FGtatsuro/53348aba74d3ee368821328e5d97138a to your computer and use it in GitHub Desktop.
Run doctest for modules including relative import statements
# Relative import problem
# FYI: https://stackoverflow.com/questions/4047227/doctest-and-relative-imports
#
find tests -name '*.py' | \
# Filtering
grep -v -e 'init.py' -e 'config' | \
# This step may be only valid for regular package.
# https://www.python.org/dev/peps/pep-0420/
sed -e 's|.py||g' -e 's|/|.|g' | \ # This
xargs -L 1 -I {} python -c 'import {}, doctest; doctest.testmod({}, verbose=True)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment