pytest.main(['test_a.py::TestDemo','-v'])

class TestDemo:
def test_a(self,login):
print(f"a username={login}")

def test_b(self):
    print("b")

def c(self):
    print(f"c login={login}")

if name == ‘main’:
# test_a.py是当前文件名
pytest.main([‘test_a.py::TestDemo’,’-v’])

请问一下:pytest.main([‘test_a.py::TestDemo’,’-v’])这里是什么意思呀,而且为什么还要pytest.main?‘-v’是给权限?

pytest.main相当于在命令行执行pytest命令,里面的参数就是pytest命令的参数

  • test_a.py::TestDemo是告诉pytest要运行的测试类/方法是当前目录的test_a.py这个文件下的TestDemo类/方法
  • -v是输出更加详细的日志信息
  • 参数的含义可以在命令行使用pytest --help命令查看

明白了,谢谢老师!