Test case execution order in pytest

前端 未结 7 1776
情书的邮戳
情书的邮戳 2020-11-28 12:01

I am using pytest. I have two files in a directory. In one of the files there is a long running test case that generates some output. In the other file there is a test case

相关标签:
7条回答
  • 2020-11-28 12:26

    Make use of the '--randomly-dont-reorganize' option or '-p no:randomly' available in pytest-randomly plugin, this will just run your test in the same order as you mentioned in your module.

    Module:

    import pytest
    
    def test_three():
        assert True
    
    def test_four():
        assert True
    
    def test_two():
        assert True
    
    def test_one():
        assert True
    

    Execution:

    (tmp.w95BqE188N) rkalaiselvan@dev-rkalaiselvan:~/$ py.test --randomly-dont-reorganize test_dumm.py
    ======================================================================== test session starts ========================================================================
    platform linux2 -- Python 2.7.12, pytest-3.10.1, py-1.5.4, pluggy-0.7.1 -- /tmp/tmp.w95BqE188N/bin/python2
    cachedir: .pytest_cache
    Using --randomly-seed=1566829391
    rootdir: /home/rkalaiselvan, inifile: pytest.ini
    plugins: randomly-1.2.3, timeout-1.3.1, cov-2.6.0, mock-1.10.0, ordering-0.6
    collected 4 items
    
    test_dumm.py::test_three PASSED
    test_dumm.py::test_four PASSED
    test_dumm.py::test_two PASSED
    test_dumm.py::test_one PASSED
    
    (tmp.w95BqE188N) rkalaiselvan@dev-rkalaiselvan:~/$ py.test -p no:randomly test_dumm.py
    ======================================================================== test session starts ========================================================================
    platform linux2 -- Python 2.7.12, pytest-3.10.1, py-1.5.4, pluggy-0.7.1 -- /tmp/tmp.w95BqE188N/bin/python2
    cachedir: .pytest_cache
    Using --randomly-seed=1566829391
    rootdir: /home/rkalaiselvan, inifile: pytest.ini
    plugins: randomly-1.2.3, timeout-1.3.1, cov-2.6.0, mock-1.10.0, ordering-0.6
    collected 4 items
    
    test_dumm.py::test_three PASSED
    test_dumm.py::test_four PASSED
    test_dumm.py::test_two PASSED
    test_dumm.py::test_one PASSED
    
    0 讨论(0)
提交回复
热议问题