Skip to content

Instantly share code, notes, and snippets.

@jotafeldmann
Last active November 24, 2020 06:17
Show Gist options
  • Save jotafeldmann/e8ee40be849afb3260936d78f543db0e to your computer and use it in GitHub Desktop.
Save jotafeldmann/e8ee40be849afb3260936d78f543db0e to your computer and use it in GitHub Desktop.
Python: set same import context for ./src and ./tests
# Expected folder structure
#
# ./project
# src/
# tests/
#
# Put this file inside ./project/tests
#
# Then, for every test file inside ./project/tests:
# from src.package import function
#
# Original source: https://docs.python-guide.org/writing/structure/#test-suite
# Adapted by https://github.com/jotafeldmann
# https://gist.github.com/jotafeldmann/e8ee40be849afb3260936d78f543db0e
import os
import sys
sys.path.append(os.path.abspath(
os.path.join(os.path.dirname(__file__), '../src')))
@jotafeldmann
Copy link
Author

Tested with Python 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment