Skip to content

Instantly share code, notes, and snippets.

@mattnorris
Created March 29, 2013 19:02
Show Gist options
  • Save mattnorris/5272868 to your computer and use it in GitHub Desktop.
Save mattnorris/5272868 to your computer and use it in GitHub Desktop.
Update the system path in a Python script to find "local" files within a project. This is especially helpful for unit testing.
"""
Given the following directory structure:
project-name
docs
scripts
src
lib
test
input
output
unit
Where the current file resides in 'test/unit'...
"""
# Get the relevant paths of the modules and tests.
CURR_PATH = os.path.dirname(__file__)
MODULE_PATH = os.path.normpath(os.path.join(CURR_PATH, '../../src/'))
OUTPUT_PATH = os.path.normpath(os.path.join(CURR_PATH, '../output'))
INPUT_PATH = os.path.normpath(os.path.join(CURR_PATH, '../input'))
# Update the system path so we can find the modules we want to test.
sys.path.append(MODULE_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment