Commit e99eeb19 authored by Bogdan's avatar Bogdan

created venv for testing.py

parent f6af0a8e
...@@ -4,7 +4,6 @@ import importlib.util ...@@ -4,7 +4,6 @@ import importlib.util
import pathlib import pathlib
import shutil import shutil
import re import re
''' '''
This script searches for all 'tests/' directories and executes all tests This script searches for all 'tests/' directories and executes all tests
by cd'ing into the dir and executing unittest discover. by cd'ing into the dir and executing unittest discover.
...@@ -12,16 +11,21 @@ It additionally installs all dependencies from a '../requirements.txt' via pip. ...@@ -12,16 +11,21 @@ It additionally installs all dependencies from a '../requirements.txt' via pip.
Use command line argument '-w' to run on windows. Use command line argument '-w' to run on windows.
''' '''
PY = sys.argv[2] if (len(sys.argv) > 1 and sys.argv[1] == '-py') else 'python' # use -py to use your own python command PY = sys.argv[2] if (len(sys.argv) > 1 and sys.argv[1] == '-py') else 'python3.7' # use -py to use your own python command
ROOT = pathlib.Path(__file__).parent.parent.absolute() ROOT = pathlib.Path(__file__).parent.parent.absolute()
REPORTS = ROOT / 'reports' REPORTS = ROOT / 'reports'
TESTS_FOLDER_NAME = os.path.normpath("/tests") TESTS_FOLDER_NAME = os.path.normpath("/tests")
print("Creating VENV")
os.system(f"{PY} -m venv venv")
PY = f"~/smart/venv/bin/{PY}"
print("\nSearching for tests at the path: "+ str(ROOT)) print("\nSearching for tests at the path: "+ str(ROOT))
count = 0 count = 0
resultCodeList = [] resultCodeList = []
coverage_paths_set = set() microservice_coverage_paths_set = set()
for (dirname, dirs, files) in os.walk(ROOT): for (dirname, dirs, files) in os.walk(ROOT):
#I assume all the tests are placed in a folder named "tests" #I assume all the tests are placed in a folder named "tests"
...@@ -37,8 +41,8 @@ for (dirname, dirs, files) in os.walk(ROOT): ...@@ -37,8 +41,8 @@ for (dirname, dirs, files) in os.walk(ROOT):
exit_val = os.system(f"{PY} -m pip install -r ../requirements.txt") # install pip dependencies exit_val = os.system(f"{PY} -m pip install -r ../requirements.txt") # install pip dependencies
#resultCodeList.append(exit_val) #resultCodeList.append(exit_val)
#exit_val = os.system(f"{PY} -m unittest discover") # execute the tests #exit_val = os.system(f"{PY} -m unittest discover") # execute the tests
exit_val = os.system(f"python3.7 -m coverage run --append --omit=*/site-packages*,*/dist-packages* -m unittest discover") #TEST CODE COVERAGE exit_val = os.system(f"{PY} -m coverage run --append --omit=*/site-packages*,*/dist-packages* -m unittest discover") #TEST CODE COVERAGE
coverage_paths_set.add(os.path.normpath(dirname)) microservice_coverage_paths_set.add(os.path.normpath(dirname))
resultCodeList.append(exit_val) #once per folder i.e if 3 tests are in a folder and crash, there will be just one exit val resultCodeList.append(exit_val) #once per folder i.e if 3 tests are in a folder and crash, there will be just one exit val
except Exception as e: except Exception as e:
...@@ -56,8 +60,8 @@ for (dirname, dirs, files) in os.walk(ROOT): ...@@ -56,8 +60,8 @@ for (dirname, dirs, files) in os.walk(ROOT):
#cur_dir = os.path(dirname).parent() #cur_dir = os.path(dirname).parent()
os.chdir(cur_dir) os.chdir(cur_dir)
print(f"Executing coverage test in {cur_dir}") print(f"Executing coverage test in {cur_dir}")
exit_val = os.system(f"python3.7 -m coverage run --append --omit=*/site-packages* -m unittest discover") exit_val = os.system(f"{PY} -m coverage run --append --omit=*/site-packages* -m unittest discover")
coverage_paths_set.add(os.path.normpath(cur_dir)) microservice_coverage_paths_set.add(os.path.normpath(cur_dir))
except Exception as e: except Exception as e:
print(e) print(e)
...@@ -83,7 +87,7 @@ except Exception as e: ...@@ -83,7 +87,7 @@ except Exception as e:
print("Combinging coverages") print("Combinging coverages")
counter = 0 counter = 0
for path in coverage_paths_set: for path in microservice_coverage_paths_set:
try: try:
path += '/.coverage' path += '/.coverage'
original = os.path.normpath( path ) original = os.path.normpath( path )
...@@ -96,11 +100,20 @@ for path in coverage_paths_set: ...@@ -96,11 +100,20 @@ for path in coverage_paths_set:
except Exception as e: except Exception as e:
print(e) print(e)
continue continue
try:
coverage_xml_path = os.path.normpah( str(REPORTS) + '/coverage.xml')
os.remove(coverage_xml_path)
coverage_html_path = os.path.normpah( str(REPORTS) + '/htmlcov' )
os.rmdir(coverage_html_path)
except Exception as e:
print(e)
print("Generating Combined report") print("Generating Combined report")
os.system("python3.7 -m coverage combine") os.system(f"{PY} -m coverage combine")
os.system("python3.7 -m coverage xml") os.system(f"{PY} -m coverage xml")
os.system("python3.7 -m coverage html") #if you want to generate the html as well os.system(f"{PY} -m coverage html") #if you want to generate the html as well
firstError = -1 firstError = -1
i = 0 i = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment