PaxPrz
PaxPrz

Reputation: 1928

Pytest: run test one by one

I've multiple test functions created in a file. Example:

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

def testB():
   assert action == fail

## Multiple other tests...

By default, user are denied for action. When I run testB individually, it passes. When I run the test file as a whole.

pytest testfile.py

The testB fails. When I debug the user permission is allowed. Seems like testA is making issue in testB. Is there a way to tell pytest to run test one after another?

Upvotes: 1

Views: 2982

Answers (2)

jaksco
jaksco

Reputation: 551

I was looking for this also

  --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.

Upvotes: 0

KennetsuR
KennetsuR

Reputation: 788

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 ===========================

Upvotes: 2

Related Questions