I've looked at most every link regarding relative imports and especially those with regard to top-level-packages, but I'm still having a ton of trouble getting my relative import code to work. For reference, I'm using Python 3.6.
I have a directory of tests that I want to run, isolated in their own directory, tests. I want to import all of the modules package into one file called InputTests.py. Here is the format of my project directory.
Within InputTests.py, I attempt to import modules this way:
from .. import modules
I get the error:
File "/Users/wfehrnstrom/Desktop/meeting_minutes/tests/InputTests.py",
line 2, in <module>
from .. import modules
ValueError: attempted relative import beyond top-level package<code>
However, I'm using the command: python -m tests.InputTests
, which supposedly tells the interpreter to run everything from my top level directory. So I guess my question is, why does my relative import statement not work given the fact that I am running this from the package above. This stack overflow post seemed to detail what I need, but their solution, running with -m doesn't work for me: How to do relative imports in Python?
In addition, there seems to be a contradiction to this in this stack overflow post: Relative importing modules from parent folder subfolder
The latter post seems to suggest that the contextual meaning of .. and . do not change based on where you execute your Python command, however the former says that it does. This has me extremely confused. Can anyone both clarify relative imports and resolve this discrepancy? Thank you.