簡體   English   中英

Pytest:一一運行測試

[英]Pytest: run test one by one

我在一個文件中創建了多個測試函數。 例子:

def testA():
   change_user_permission_to_allow()
   assert action == success
   change_user_permission_to_deny()

def testB():
   assert action == fail

## Multiple other tests...

默認情況下,用戶被拒絕執行操作。 當我單獨運行testB時,它通過了。 當我作為一個整體運行測試文件時。

pytest testfile.py

testB失敗。 當我調試時,允許用戶權限。 似乎testAtestB中出現問題。 有沒有辦法告訴 pytest 一個接一個地運行測試?

import pytest

@pytest.mark.order2
def test_foo():
    assert True

@pytest.mark.order1
def test_bar():
    assert True
$ py.test test_foo.py -vv
============================= test session starts ==============================
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- env/bin/python
plugins: ordering
collected 2 items

test_foo.py:7: test_bar PASSED
test_foo.py:3: test_foo PASSED

=========================== 2 passed in 0.01 seconds ===========================

我也在找這個

  --sw, --stepwise      exit on test failure and continue from last failing
                        test next time
  --sw-skip, --stepwise-skip
                        ignore the first failing test but stop on the next
                        failing test.
                        implicitly enables --stepwise.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM