问题标签 [conftest]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 如何在 python selenium 中为每个测试启动单独的浏览器
在运行 test_login.py 时,应该启动 3 个浏览器并验证测试,但只有一个正在启动,第二个测试失败,因为第二个在第一个测试步骤之后继续。
*********** Conftest.py********** 下面是conftest文件
test_login.py这个测试文件包含 3 个测试来验证
******* PageLogin *********** 这是定义所有 xpath 的登录页面
unit-testing - Conftest 使用 Pytest 和 MonkeyPatch.setattr 更改函数和变量
我有以下脚本:
(1) 在utils.database_helper.py
:
这里,在database_helper.py
两个 db 变量中都是使用原始函数来获取 Oracle 连接的。现在:
(2) 在conftest.py
:
有test.py
所以它读取第setup_database
一个,带有一个可以在database_helper
某处导入的加载器。
测试脚本假设覆盖get_database_connection
函数,然后db1
可以db2
基于新替换的函数工作。
测试通过上述设置。但是,如果我去:
会出现错误,显示:
我检查了日志,似乎第一次运行,database_helper.py
然后被分配了 Oracle 连接。然后,即使monkeypatch完成了函数模拟,当再次调用它们时,它们也不会应用假设要覆盖的新模拟函数,而是它们仍然跟随Oracle连接而不是测试连接。db1
db2
db1
db2
get_database_connection
有没有办法只编辑conftest.py
来解决?
python-3.x - Pytest 夹具在使用从 yamls/json 加载的参数化值时忽略范围
我正在使用 pytest 运行测试。
我想在一个模块中所有定义的测试之前运行一个前置条件,所以我创建了一个前置条件函数并用 pytest.fixture
with修饰它,scope = "module"
因此它只会对模块中的所有测试执行一次。这个先决条件需要另一个夹具test_target
来为测试做准备。除此之外,他们自己的测试功能也使用了test_target
以及test_param
从 yaml 文件中加载的另一个。
要测试的设备总是在包含要测试的目标信息的 devices.yaml 文件中定义,因此我正在参数化yaml 文件中加载的数据test_target
。 test_param
我遇到的问题是,我定义为在模块范围内运行的前提条件是在函数范围内运行。
我注意到,当我直接将字典分配给 test_target 以进行参数化时,前提条件的行为符合预期(模块范围),但是我需要对设备信息进行硬编码。
我究竟做错了什么?也许还有另一种解决方法来执行这个前提条件?我已经用 json 试过了,我的行为与 yaml 完全相同
我的设置使用:
- WSL-Ubuntu 20.04
- 蟒蛇3.9
- pytest 6.2.5
我的示例测试树:
站.yaml
站.json
conftest.py
测试1.py
测试2.py
在我得到这个输出之前,当我在代码中运行测试时
而如果我直接运行测试并分配加载的值(在 conftest.py 中取消注释行)
我得到以下输出:
selenium - Unable to use pytest fixture value in base class
I have requirement where i have to take language from the command line and do validation based on selected language here is my code conftest.py
I want to use this langugae in testfile so i am calling it like this way test_login.py
This is the function where i want to use the entered languague base.py
constant.py
however i am getting an error: