Skip to content

Instantly share code, notes, and snippets.

@nettle
Created August 6, 2019 15:03
Show Gist options
  • Save nettle/882554a7ef0389c362936fe4a4ede98d to your computer and use it in GitHub Desktop.
Save nettle/882554a7ef0389c362936fe4a4ede98d to your computer and use it in GitHub Desktop.
TestCase sample which loads module from directory above
"""
TestCase sample which loads module from directory above
implementing the following directory structure:
sample.py
test/test_sample.py
"""
import imp
import os
import sys
import unittest
# Disable *.pyc files
sys.dont_write_bytecode = True
class TestOne(unittest.TestCase):
"""Unittest class for one module"""
@classmethod
def setUpClass(cls):
"""Load module"""
module_name = "sample.py"
module_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), os.pardir, module_name))
cls.sample = imp.load_source(module_name, module_path)
def test_one(self):
"""Test one"""
self.assertTrue(TestOne.sample.someFunction())
def test_two(self):
"""Test two"""
self.assertTrue(2 == 2)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment