I created a test_main.py file to unit test the main.py file. But every time I click "Run", it only runs the main.py file. Is it possible to run a file other than the main file?
import test_main at the beginning of main.py to run test_main.py.
Please upvote this comment if it was helpful or useful in any way
I am trying to run a unit testing code from the file test_main.py, as you can see here: https://repl.it/@LeonGrin/Unit-Testing-in-Python-with-Replit
This repl is very simple. I am trying to figure out a way to run unit testing on Repl.it without having to insert all the unit testing code on the main.py file. Do you know how can I do this?
I feel that it might exist a very simple solution to my problem that I am not seeing.
I solved this problem like this:
Just use python os.system to get access to console commands
# main.py import os os.system('python3 -m pytest -v test_api.py')
In general case
os.system('python3 -m <name_of_file>.py')
In case someone is looking to simply run a file use:
#main.py import os os.system('python3 <filename>.py')