0

I want to use a specific method to be run using py.test, and I have seen several suggestions like HERE and HERE, but for some reasons these answers do not work.

I have a file mytest.py which has a method special_test which I want to start with py.test. And neither

py.test mytest.py::special_test

nor

py.test mytest.py -k special_test

do work.

In the first example I get an ERROR: not found and in the second example it just says no tests ran.

What am I missing here?

Content of mytest.py:

def special_test():
    assert True
4
  • By default, test functions have to start with test_, otherwise they won't be recognized as a test (this can be changed, though). As an aside: using py.test is long deprecated, use pytest instead. Commented Nov 3, 2022 at 11:42
  • @MrBeanBremen This information seems to be missing from the linked documentation. However, how to run a test with a method that does NOT start with test_?
    – Alex
    Commented Nov 3, 2022 at 11:47
  • As shown in the linked documentation, you have to adapt your pytest.ini (for example by setting python_files = *.py). Commented Nov 3, 2022 at 12:24
  • As for the doucmentation - it is there, but not easy to find if you don't know where to look. This could certainly be linked from the usage part... Commented Nov 3, 2022 at 12:30

0

Browse other questions tagged or ask your own question.