0
votes

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

1
When you "run the test file," does it actually run as a PyTest configuration? Can you add a screenshot? - user2762956
It just outputs "Process finished with exit code 0" the normal PyCharm output. - QFII
It still sounds like it's not running as a PyTest configuration, just as a regular Python file. After you changed the default test runner, did you delete the old run configuration and recreate a new one? - user2762956
Ah that might do the trick, not sure how exactly to do that? - QFII

1 Answers

1
votes

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.