51Testing软件测试论坛
标题:
跨模块使用pytest dependency时,依赖不生效
[打印本页]
作者:
cappuccino91
时间:
2021-3-29 11:21
标题:
跨模块使用pytest dependency时,依赖不生效
有两个模块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
复制代码
作者:
郭小贱
时间:
2021-3-30 16:26
参考这篇博文看下
https://blog.51cto.com/9605182/2450589
作者:
jingzizx
时间:
2021-3-30 18:50
单步调试
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2