pytest collecting test cases but not executing the script

845 Views Asked by At

enter image description here

I am trying to run a pytest script like this :

pytest myfile.py -m marker_name -v -s --disable-warnings

pytest.ini contains the marker name as :

[pytest]
markers =
    marker_name: run marker_name scenario

But I am getting the above output. The marker seems to have been collected but is deselected. Can anyone provide any insights onto this?

1

There are 1 best solutions below

0
On

To me it looks like you did not add the marker to the test file at all. From your description how you run the test file, you would only run the tests, marked with the marker_name, but you do not have any tests marked correctly.

You need to mark the tests with @pytest.mark.marker_name.

I use for example following marker in my pytest.ini file:

markers =
    soup: marks tests as soup tests (deselect with '-m "not soup"')

In my "test_dummy.py" file I use the marker like that:

@pytest.mark.soup
def test_software_lib_of_unkown_provenance():
    ## some code

To exclude the soup tests I run:

pytest myfile.py -m "not soup"

To only run the soup tests I do:

pytest myfile.py -m soup

See also here: https://docs.pytest.org/en/6.2.x/example/markers.html