command-linepytestfile-search

How to count test cases written with pytest?


My objective is to get the number of test methods in a package/folder. I'm able to do that by executing

py.test <folder> --collect-only|grep collected

This shows the test count as

collected 104 items

However this counts the parameterized test multiple times,e.g. if a method has two sets of parameter single test will be counted 2 times. Is there any way to tell pytest to count them as single?


Solution

  • How about

    find . -type f -name 'test*.py' -exec grep -e 'def test_' '{}' \; | wc -l
    

    or

    ag 'def test_' | wc -l