So I am using python and I have the following schema of files:
- 10.Testing (parent folder)
— files (folder)
|__ init.py (empty file)
|simple_functions.py
— tests (folder)
| test_simple_functions.py
|__ init.py (empty file)
10.Testing: This is my parent folder, which contains the 2 folders, tests and files.
files: This is a subfolder in my parent folder. It contains the Python file simple_functions.py where I have defined some functions.
tests: This is another subfolder in my parent folder. It contains the Python file test_simple_functions.py where I am writing my test cases for my functions in simple_functions.py.
Just to clarify, I am not 100% if this should be the file structure of a repo. If not please do tell.
In the test_simple_functions.py I have added the following code :
# testing the file simple_functions.py
from files.simple_functions import *
def main():
squared_function(2)
if __name__ == '__main__':
main()
So I am using VS Code and trying to execute the code of simple_functions.py but I cannot it says:
Traceback (most recent call last):
File “teststest_simple_functions.py”, line 3, in
from files.simple_functions import *
for example from workspace folder:
py tests/test_simpl_functions.py
from tests folder:
tests> py .test_simple_functions.py
No matter where I run the file:
whether I am in tests folder, workspace folder, files folder it doesn’t work.
but in my test_simple_functions.py
My workspace / exporer says parent file 10.Testing
I tried terminal bash , powershell and cmd.
it highlights the “files.simple_function” in light blue/green (not sure about the color lol) and VS code recognises that there are functions there and I can use them and tab them to autocomplete , so what is the problem ?
What should I be doing ?
is this the best practise?
I tried running the code in multiple folders and testing the code it doesnt work but recognises it in vs code
FNG_mw2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.