Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I can run the tests by executing (on Windows)

pytest .\tests\test_x.py

Result:

================================= test session starts ==================================

platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1

rootdir: C:\Users\......

collected 9 items

tests\test_x.py .........                                                         [100%]

================================== 9 passed in 3.67s ===================================

These are the following two commands

pytest -m tests

pytest -m test

This is the result i got. My question is why all my tests are deselected while they can be run as a script?

PS C:\Users\......> pytest -m test

================================= test session starts ==================================

platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1

rootdir: C:\Users\......

collected 9 items / 9 deselected

================================ 9 deselected in 3.78s =================================

3 Answers

0 votes
by (36.8k points)

You're using the -m which filters which tests to run according to how you mark your tests. You're telling a pytest to only run tests tagged @pytest.mark.test.

Presumably, you don't have any tests marked as such.

Want to be a master in Data Science? Enroll in this Data Scientist

0 votes
by (340 points)
You can want to run all tests, simply use pytest or pytest.\tests\test_x.py without -m option.

 If you intend to run tests that are marked, you have to write your test functions with right marker

import pytest

@pytest.mark.test
def test_case():
    assert True

After adding the marker, running pytest -m test will include those tests

You can also check all the exiting markers in your tests by running pytest –markers
0 votes
by (340 points)

You can want to run all tests, simply use pytest or pytest.\tests\test_x.py without -m option.

If you intend to run tests that are marked, you have to write your test functions with right marker

import pytest

@pytest.mark.test
def test_case():
assert True

After adding the marker, running pytest -m test will include those tests

You can also check all the exiting markers in your tests by running pytest –markers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...