Skip to content

Ramblings and Thoughts

  • About

Ramblings and Thoughts

Networking, Computers, Life

Configuring PyCharm for using pytest as the test runner

January 30, 2019 by cbogdon

To use pytest as the test runner, I found a bunch of things that weren’t working officially, so I tried to write this blog post to understand the right way of doing it.

Configuring pytest as the test runner

To configure pytest, you need to do the following:

  1. Go to the Preferences menu ( Within Mac OSX, click on the PyCharm name in the menu bar and then select preferences)
  2. Click on Tools->Python Integrated Tools
  3. Under the testing section, select “pytest” under the default test runner field.

Create a new testing file within a project

  1. Open up or create a new project in PyCharm
  2. Create or open a python file (which represents the application you want to test). For example, “testfile.py
  3. Make a directory a directory called tests within the current project
  4. Create a simple test file. Ensure that the name begins or ends with test (ie., test_*.py or *_test.py
  5. For example:
import testfile
import pytest


class TestFunctions(object):
    def test_num1(self):
        assert True == True

This next section is the one part that I missed that caught me off guard.

Edit a Configuration for the testing module

  1. Go to Run -> Edit Configurations
  2. On the top left of the window, click on the ‘+’ module to add a new configuration.
  3. Select the “Python Tests” menu followed by “pytest“
  4. Select the testing file that we want to test with pytest in both the “Working Directory” and “Script Path”
  5. The following window shows a very simple example.

Run Testing Module

  1. From the Run menu select the Run choice
  2. Select the name of the module that we want to test
  3. PyCharm will now show the testing output.
  4. For example:

Post navigation

Previous Post:

Managing Ubuntu Packages

Next Post:

Python testing notes with pytest

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tags

Apache Carbon Copy Cloner Chrome Cisco Crashplan HTML iOS iClou Linux MySQL Nexus NXAPI Omnifocus OSX Outlook PyCharm Pytest Python Quicken Samsung TV Ubuntu VMWare Wordpress Youtube
© 2025 Ramblings and Thoughts | WordPress Theme by Superbthemes