|
有两个模块A和B,A的测试用例被B的测试用例依赖,执行B的测试用例时,A的测试用例执行了,但是B的测试用例跳过了,不知道什么原因
B模块代码
- import pytest
- import sys, os
- sys.path.append(os.getcwd())
- from testcases.test_xdist_2 import TestXdist2
- # from pytest_dependency import depends
- class TestXdist1():
- def setup_class(self):
- self.x = TestXdist2()
- @pytest.mark.dependency(depends=["aa"], scope="module")
- def test_t2(self):
- print("\ntest_t2")
- assert 1==1
- if __name__ == "__main__":
- pytest.main(["-s", "-v", f"{os.path.abspath('testcases')}/test_xdist_1.py"])
复制代码
A 模块代码
import pytest
- class TestXdist2():
- @pytest.mark.dependency(name="aa")
- def test_t1(self):
- print("\ntest_1")
- assert True
复制代码
执行结果如下:
- PS D:\gitProjects\selenium_pytest_demo> & D:/Python38/python.exe d:/gitProjects/selenium_pytest_demo/testcases/test_xdist_1.py
- Test session starts (platform: win32, Python 3.8.7, pytest 6.2.2, pytest-sugar 0.9.4)
- cachedir: .pytest_cache
- metadata: {'Python': '3.8.7rc1', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'pytest': '6.2.2', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'allure-pytest': '2.8.35', 'dependency': '0.5.1', 'forked': '1.3.0', 'html': '3.1.1', 'metadata': '1.11.0', 'rerunfailures': '9.1.1', 'sugar': '0.9.4', 'xdist': '2.2.1'}, 'JAVA_HOME': 'D:\\Java\\jdk-15.0.1'}
- rootdir: D:\gitProjects\selenium_pytest_demo, configfile: pytest.ini
- plugins: allure-pytest-2.8.35, dependency-0.5.1, forked-1.3.0, html-3.1.1, metadata-1.11.0, rerunfailures-9.1.1, sugar-0.9.4, xdist-2.2.1
- collecting ...
- testcases\test_xdist_1.py::TestXdist1.test_t2 s 50% █████
- test_1
- testcases\test_xdist_2.py::TestXdist2.test_t1 ✓ 100% ██████████
- Results (0.04s):
- 1 passed
- 1 skipped
复制代码 |
|