【问题标题】:Pytest Exit CodesPytest 退出代码
【发布时间】:2022-06-13 20:44:18
【问题描述】:

我以以下方式构建了我的 pytest 类:

class Test_Exit_Code(object):
    
  def setup_class(cls):
      If 2==2:
         # stop execution of the test class


  def test_a(self):
     assert True==True

正如您在 setup_class 方法中看到的那样,我插入了一个 IF ,我想在 if 部分中实现的是,如果某个条件似乎为真,而不是我想返回退出代码 5 的注释,即没有收集任何测试。 到目前为止,我还没有找到任何方法。

【问题讨论】:

  • 我不认为你可以这样做:当 setup_class 运行时,pytest 已经完成了收集阶段。

标签: python-3.x pytest exit-code


【解决方案1】:

您可以尝试拨打pytest.exit()。此外,您似乎缺少 classmethod 装饰器

class Test_Exit_Code:
  @classmethod
  def setup_class(cls):
      If 2==2:
         pytest.exit("test exit code setup failed", returncode=5)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多