0

I have the following project structure and I am working with remote deployment with Pycharm.

source/
+- src/  
   +- __init__.py
   +- abcd.py
+- test/
   +- __init__.py
   +- tests.py 

In tests.py, I import src.abcd.
Running unittest in terminal with python -m unittest test.tests in the source folder is OK. But when I run the unittest in Pycharm, it says No module named 'src.abcd'.
If I remove the __init__.py in source/test folder, Pycharm is OK but terminal reports error No module named 'test/tests'.

Is there anyway to run unittest with both the commandline and Pycharm?

  • Looks like it doesn't know the PYTHONPATH? – Lou Franco Dec 09 '22 at 02:13
  • You say: "If I remove the `__init__.py` in `source/test` folder, Pycharm is OK" -- is this really true? Is it just running 0 tests? – Lou Franco Dec 09 '22 at 02:15
  • Consider making an [installable package](https://stackoverflow.com/q/62498127). – bad_coder Dec 09 '22 at 02:46
  • Sorry I missed some information that I thought is unimportant. There is a `__init__.py` in the `source` folder and the `source` folder has the same name with the `src`. So I think it is because Pycharm is confused by the folder names. I changed the folder name of `src` and the problem is solved! – Wang Xiaoming Dec 09 '22 at 06:42

0 Answers0