Test case execution order in pytest

前端 未结 7 1848
情书的邮戳
情书的邮戳 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:12

    main.py:

    import functools
    import pytest
    from demo import test_foo,test_hi
    
    def check_depends(depends):
        try:
            for dep in depends:
                dep()
        except Exception as e:
            return dep
        else:
            return True
    
    def pytest_depend(depends):
        def pytest_depend_decorator(func):
            stat = check_depends(depends)
            if stat is True:
                return func
            else:
                return pytest.mark.skip(True, reason="%s[skip] --> %s[Failed]" % (func.__name__, stat.__name__))(func)
        return pytest_depend_decorator
    
    
    @pytest_depend([test_foo,test_hi])
    def test_bar():
        pass
    
    @pytest_depend([test_foo,test_hi])
    def test_bar2():
        pass
    

    demo.py:

    def test_hi():
        pass
    def test_foo():
        assert False
    

    platform linux -- Python 3.5.2, pytest-3.8.2, py-1.6.0, pluggy-0.7.1 -- /usr/bin/python3

    pytest -vrsx ./plugin.py

提交回复
热议问题