PYTHONPATH for tests in CLion

In my project (which is a mixed C++/Python source tree) we have this structure:

src/

    a.py

    b.py

    tests/

        atest.py

        btest.py

 

In PyCharm I have marked both the src and tests directories as Source roots.  This allows me to run tests with the correct PYTHONPATH.   It's actually kindof tricky to set this up - you have to mark the subdirectory before the parent directory.

I saw some changes were made in CLion 2016.3 with PYTHONPATH so I tried doing the same thing (marking the directories as Project Sources and Headers).  My test's run configuration has both boxes checked for Add Source Roots to PYTHONPATH and Add Content Roots to PYTHONPATH.    But when I try to run the test it can't find the classes from the parent directory.

How can I set this up in CLion?  Also, what is the difference between a Source Root and a Content Root?   I can't find anything on how to set a Content root.

Thanks,

3
3 comments

I fixed it by editing the Run Configuration and checking the box "Add SOURCE roots to PYTHONPATH." You need to mark the python sources directory as a source folder.

2
Avatar
Permanently deleted user

I managed to get this to work, finally. The trick is to set up a virtualenv and then put your changes to e.g. PYTHONPATH in the activate script. Then have CLion use the python inside the virtualenv. This made it possible to find all the local files associated with the project.

0

Please sign in to leave a comment.