Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to mark a directory as test sources root in PyCharm

I was trying to mark a directory as test sources root in PyCharm so that I don't have to manually set the target directory for my generated test file every time. When I right-click my "tests" directory I only see the following four options:

Mark Directory As: 1. Source Root 2. Template Folder 3. Excluded 4. Resource Root

I remember doing this in Intellij for Java but is this not possible for PyCharm?

like image 812
TheInvisibleFist Avatar asked Feb 16 '16 00:02

TheInvisibleFist


People also ask

What does Mark directory as sources root do?

In Pycharm, if you right click in a folder inside your project, you can mark it as sources root , so then you can import modules from this folder and subfolders.

How does PyCharm choose working directory?

Once PyCharm is open, set up the project. Go to File->Open and select the root directory in which both your source and build directories reside.

What is source root directory?

The project source directory is typically the topmost, or “root” directory that contains most of the source files. You might think of this as the “home” directory of the project. Source Insight normalizes project file names relative to this directory.


1 Answers

Do the following:

  1. Mark the directory as "sources".
  2. Close PyCharm.
  3. Open the <project root>/.idea/<projectname>.iml file in a text editor.
  4. Search for "isTestSource=" for the appropriate directories and change it from "false" to "true".
  5. Reopen PyCharm.
like image 117
Marco Avatar answered Sep 21 '22 17:09

Marco