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
Alex
  • 41,580
  • 88
  • 260
  • 469
  • By default, test functions have to start with `test_`, otherwise they won't be recognized as a test (this [can be changed](https://docs.pytest.org/en/6.2.x/example/pythoncollection.html?highlight=discovery#changing-naming-conventions), though). As an aside: using `py.test` is long deprecated, use `pytest` instead. – MrBean Bremen Nov 03 '22 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 Nov 03 '22 at 11:47
  • As shown in the linked documentation, you have to adapt your `pytest.ini` (for example by setting `python_files = *.py`). – MrBean Bremen Nov 03 '22 at 12:24
  • As for the doucmentation - it is [there](https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#conventions-for-python-test-discovery), but not easy to find if you don't know where to look. This could certainly be linked from the usage part... – MrBean Bremen Nov 03 '22 at 12:30

0 Answers0