Notes on setting up a new project in PyCharm. I forget between projects.

I had occasion yesterday to set up a new little PyCharm project. As always, I want a reasonable starting structure, with tests and source in separate folders and a config that runs the tests. It took me far too long and cost me far too much frustration to get it working. So here are some notes for next time.

Here’s a PyCharm project creation window. You could select the Git option if you are so inclined: happens that I did that later.

creation

Here is my folder setup. Comments follow.

folders

The venv folder was created by PyCharm and I have not changed it. I created tst and src as new Python Package files, by right clicking the linkage top folder. I am not certain whether these need to be packages or not, but this works.

Production files will go under src and test files under tst. I hope this does not surprise me later.

It seems that pytest files must be named beginning with ‘test_’.

I created the first such file with import pytest at the top and PyCharm installed pytest. And after you create the test, you can run it by clicking the green wedges in the editor. That works but only runs whatever you click. If you’re me, you want to be able to run all the tests. For that, we need a config file.

config

Above is the config file that I use to run pytest. I do not know how it knows to run pytest. I only know that it works.

Now I’ll create a new little project following what I think are the rules, and see what breaks.

The process worked. Here are the screenshots:

project creation window

folders with first test file

config add

Note that you select what kind of config. Select pytest.

blank config

select the folder icon, find your project

same path in script and working directory

tests run ok

best to leave this run option in.

OK. With luck I’ll remember that I have this.