Skip to main content
Active reading [<https://en.wikipedia.org/wiki/History_of_Python#Version_3> <https://www.youtube.com/watch?v=1Dax90QyXgI&t=17m54s>]. Used more standard formatting (as a result the diff looks more extensive than it really is - use view "side-by-side Markdown" to compare).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

As Paolo said, we have 2two invocation methods:

1) python -m tests.core_test 2) python tests/core_test.py 
  1. python -m tests.core_test
  2. python tests/core_test.py

One difference between them is sys.path[0]the sys.path[0] string. Since the interpret will search sys.pathsys.path when doing import, we can do with tests/core_test.py:

if __name__ == '__main__': import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from components import core <other stuff> 

And more after this, we can run core_test.pycore_test.py with other methods:

cd tests python core_test.py python -m core_test ... 
cd tests python core_test.py python -m core_test ... 

Note, py36 tested only on Python 3.6.

As Paolo said, we have 2 invocation methods:

1) python -m tests.core_test 2) python tests/core_test.py 

One difference between them is sys.path[0] string. Since the interpret will search sys.path when doing import, we can do with tests/core_test.py:

if __name__ == '__main__': import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from components import core <other stuff> 

And more after this, we can run core_test.py with other methods:

cd tests python core_test.py python -m core_test ... 

Note, py36 tested only.

As Paolo said, we have two invocation methods:

  1. python -m tests.core_test
  2. python tests/core_test.py

One difference between them is the sys.path[0] string. Since the interpret will search sys.path when doing import, we can do with tests/core_test.py:

if __name__ == '__main__': import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from components import core <other stuff> 

And more after this, we can run core_test.py with other methods:

cd tests python core_test.py python -m core_test ... 

Note, tested only on Python 3.6.

Source Link
zhengcao
  • 481
  • 6
  • 4

As Paolo said, we have 2 invocation methods:

1) python -m tests.core_test 2) python tests/core_test.py 

One difference between them is sys.path[0] string. Since the interpret will search sys.path when doing import, we can do with tests/core_test.py:

if __name__ == '__main__': import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from components import core <other stuff> 

And more after this, we can run core_test.py with other methods:

cd tests python core_test.py python -m core_test ... 

Note, py36 tested only.