I am trying to write a code which runs unittest case files and extract the performance of test cases run . Below is my current code
def run_tests(root, file):
os.chdir(root)
command = ['python', '-m', 'unittest', file]
output = subprocess.run(command, stdout=subprocess.PIPE, stderr= subprocess.PIPE, shell = True, text = True)
I am running the above function by passing two parameters root and file .
file is tesfile created by unittest whereas root is the directory path where my test files resides. now the above code works perfectly fine for most of the cases.
But in cases where my source code and my test files are not directly in same folder, the error arises.
Suppose my directory is something like below
Calendar
Calendar1
Calendarcheck
check.py
process_out.py
tests
tests1.py
tests2.py
In such cases if i give path of root like Calendar/Calendar1/tests and filename as tests1.py , it gives me error since I am importing some function from check.py in tests1.py
I also tried giving root as Calendar/Calendar1 and filename as tests/tests1.py , but it is giving me error