QFII
QFII

Reputation: 71

Running PyTest Tests in Pycharm

I am working on writing tests for my python code. I explored unit tests and decided to use PyTest. I am using PyCharm for my IDE to run/debug my python code.

However, when I run the test file that I created, it does not output anything in the PyCharm output. I have read about similar issues here. As a result, I went into the PyCharm preferences and changed the default testing from unit test to PyTest. However, this did not seem to fix the problem. I am a little unsure of how to get this to display the desired output. I imagine if I were to run this in the terminal the output would display properly. I am just having trouble seeing it in PyCharm.

Although it is not really relevant, the python code file I am testing is a simple definition of a function that computes the fibonacci sequence. The test file, aptly named, test_fib then tests it. Everything runs properly, but the traditional PyTest output (all tests passed etc.) is not displaying.

Any suggestions? I can add additional information or details if necessary.

Thanks.

EDIT:

I have included a snapshot to illustrate more or less the expected output:

enter image description here

Upvotes: 0

Views: 3230

Answers (1)

user2762956
user2762956

Reputation: 150

Considering you've changed the default runner to pytest, per your reference, new "Configurations" should now use that setting. However, old/existing ones will not.

Change the Default test runner

Assuming you've already done this, but for completeness sake:

  1. Go to File > Settings
  2. Go to Tools > Integration Tools
  3. Under Default test runner, change it to pytest
  4. Click OK

Recreating a Configuration

To delete an existing Configuration:

  1. Go to Run > Edit Configurations. This should bring up the "Run/Debug Configurations" dialog box.
  2. Find and select the configuration you'd like to delete
  3. Click the - icon on the upper-left corner of the "Run/Debug Configurations" dialog box.
  4. Click OK on the bottom-right corner of the dialog box.

To create a new Configuration:

  1. Right-click on your pytest file
  2. Select Run 'pytest in <your pytest file name>...'

More information about Configurations

These are my Configurations:

enter image description here

Notice:

  • "export_order" is just a "Python" Configuration
  • "pytest in auth_integration_test.py" is a "Python test" type of Configuration

When a pytest Configuration is run, it should look something like this:

enter image description here

References

JetBrains' PyCharm/Pytest help page: https://www.jetbrains.com/help/pycharm/pytest.html

Side Note

In addition, notice one of the comments in the link you provided suggests manually creating a pytest configuration. That, technically, answers your question, too.

Upvotes: 5

Related Questions