P粉8271215582023-08-22 14:11:27
To elaborate on Ignacio Vazquez-Abrams’s answer:
Python’s import mechanism is __name__
relative to the current file. When a file is executed directly, its name is not the usual name, but "__main__"
is used as the name. Therefore, relative imports don't work.
As Ignacio suggested, you can execute it using the -m
option. If part of your package is run as a script, you can also use the __package__
attribute to tell the file what name it should have in the package hierarchy.
For more information, please see http://www.python.org/dev/peps/pep-0366/.
P粉6045078672023-08-22 09:39:36
Yes. You are not using it as a package.
python -m pkg.tests.core_test