pytest - Running tests in a class

Class A
  test 1
  test 2

If you simply run cmd >py.test
You might encounter  "No tests found" or " collected 0 tests"
The reason lies in the naming convention
  • test_ prefixed test functions or methods outside of class
  • test_ prefixed test functions or methods inside Test prefixed test classes (without an __init__ method) 
So it has to be
class Test_A():
  def test_1(self):
     ......
     ......
  def  test_2(self):
    .......
    ......

import pytest

class Test_Class():
    def test_py_1(self):        print("This is test 1")
        assert False
    def test_py_2(self):        print("This is test 2")

Comments

Popular Posts