Last active
November 24, 2020 06:17
-
-
Save jotafeldmann/e8ee40be849afb3260936d78f543db0e to your computer and use it in GitHub Desktop.
Python: set same import context for ./src and ./tests
This file contains 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
# 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'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested with Python 3.9