ApI-QA
ApI-QA

Reputation: 1

No tests collected by pytest

I have problem in importing pytest while writing a python code. "import pytest is grayed out.

Python is 3.8.3, Pycharm community edition. pytest version 5.4.2, is successfully installed and can be seen in the project interpreter in pycharm. As well as I can see the installed path of pytest in python directory.

When running py.test command from console. It starts the test run shows "collected 0 items" and lastly ends with "NO TESTS RAN IN 0.05s"

If anyone running similar problems with some other packages kindly let me know. TIA...

Upvotes: 0

Views: 3803

Answers (2)

alexzshl
alexzshl

Reputation: 1117

Running pytest in the terminal is an option. In addition, Pycharm has integrated test suite for automatic discovery and collection of test tasks. You can use hotkey ctrl+shift+10 to run the test tasks directly in current file .

enter image description here

Upvotes: 0

Gustav Rasmussen
Gustav Rasmussen

Reputation: 3961

You simply run pytest from the commandline. There is no need to import pytest into a script. Take this Python script as an example:

def inc(x):
    return x + 1


def test_answer():
    assert inc(3) == 4

To run pytest on it, from the terminal (after changing to the right directory):

$ pytest

And you will then see the test outcome in the commandline as pytest automatically picks up the python scripts names test_*.py, where * is any name, e.g. test_increment.py. To have a test from your Python script run, name it with test_ as well to begin with.

Upvotes: 1

Related Questions