Skip to content
Snippets Groups Projects
Commit 8db2b44b authored by Sven Graupner's avatar Sven Graupner
Browse files

update to run unit tests from project directory

parent 592fef7d
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"python.testing.unittestArgs": [ "python.testing.unittestArgs": [
"-v", "-v",
"-s", "-s",
"./C_expressions", ".",
"-p", "-p",
"test_*.py" "test_*.py"
], ],
......
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
\ No newline at end of file
import os
""" """
Special file __init__.py marks a directory as a Python package. Special file __init__.py marks a directory as a Python module.
A Python Package is a collection of Python modules with an The file is executed once when any .py file is imported.
__init__.py File. The file is executed once when any .py file //
from the directory is imported for the first time. Python unittest require the presence of (even an empty) file.
""" """
# load setup module when executed in parent directory
def package_dir(file): try:
""" __import__('setup')
Return name of directory of this package. #
""" except ImportError:
path = os.path.normpath(file).split(os.sep) pass
return path[len(path)-2] # e.g. "C_expressions"
def project_path(file):
"""
Return path to project directory.
"""
path = os.path.normpath(file).split(os.sep)
return os.path.dirname(file)[:-len(PACKAGE_DIR)-1]
def import_sol_module(file):
"""
Import and return module with name "file + '_sol'".
Raises ImportError exception, if _sol file does not exist.
"""
sol_module = (file.split("\\")[-1:])[0].split(".")[0] + "_sol"
return __import__(sol_module, globals(), locals(), [], 0)
# name of this package directory
PACKAGE_DIR = package_dir(__file__)
# path to project directory, in which this module resides
PROJECT_PATH = project_path(__file__)
...@@ -61,9 +61,9 @@ class Expressions: ...@@ -61,9 +61,9 @@ class Expressions:
# attempt to load solution module (ignore) # attempt to load solution module (ignore)
try: try:
sol_module = (__file__.split("\\")[-1:])[0].split(".")[0] + "_sol" _from, _import = 'expressions_sol', 'Stream'
mod = __import__(sol_module, globals(), locals(), [], 0) mod = __import__(_from, fromlist=[_import])
mod.set_solution(self) # replace empty values with solutions mod.set_solution(self) # invoke set_solution() to replace values with solutions
# #
except ImportError: except ImportError:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment