PythonPytest-从外部接收测试参数
我是pytest框架的新手,我想知道我的pytest是否有从其他脚本接收参数的标准方法。我想最常见的做法是编写@pytest.fixture,如下所示:PythonPytest-从外部接收测试参数,python,pytest,Python,Pytest,我是pytest框架的新手,我想知道我的pytest是否有从其他脚本接收参数的标准方法。我想最常见的做法是编写@pytest.fixture,如下所示: @pytest.fixture def param(request): device = request.config.getoption("--parameter") if parameter == 'A': return value_a else: return default_value 并使用命令py.test-par
@pytest.fixture
def param(request):
device = request.config.getoption("--parameter")
if parameter == 'A':
return value_a
else:
return default_value
并使用命令py.test-parameter=value运行我的测试。该命令由其他脚本执行
但是如果我的测试需要很多参数,比如说10个参数,那将是一个很长的命令。所以我想问,在这种情况下,标准的方法是什么——我是否提供某种xml文件或序列化字典,其中包含参数,以及我的夹具,以从中获取参数
另外,我的另一个脚本将如何知道向我的测试提供什么类型的参数-在我的conftest.py中是否有保存参数信息的test_参数配置文件或一些硬编码数据,或者我应该使用从inspect import signature读取测试签名来获取参数
编辑
这是我的测试样本
class TestH5Client:
# runs before everything else in the class
def setup_class(cls, ip="11.111.111.111",
browserType="Chrome",
port="4444",
client_url="https://somelink.com/",
username="some_username",
hpassword="some_pass"):
cls.driver = get_remote_webdriver(ip, port, browserType)
cls.driver.implicitly_wait(60)
cls.client_url = client_url
cls.username = username
cls.password = password
def teardown_class(cls):
cls.driver.quit()
def test_login_logout(self):
# opening web_client
self.driver.set_page_load_timeout(60)
self.driver.get(self.h5_client_url)
# opening web_client log-in window
self.driver.set_page_load_timeout(60)
self.driver.find_element_by_css_selector("div.gettingStarted p:nth-child(4) a:nth-child(1)").click()
# log in into the client
self.driver.find_element_by_id("username").send_keys(self.h5_username)
self.driver.find_element_by_id("password").send_keys(self.h5_password)
self.driver.set_page_load_timeout(60)
self.driver.find_element_by_id("submit").click()
# clicking on the app_menu so the logout link appears
self.driver.implicitly_wait(60)
self.driver.find_element_by_id("action-userMenu").click()
# clicking on the logout link
self.driver.implicitly_wait(60)
self.driver.find_element_by_css_selector("#vui-actions-menu li:nth-child(3)").click()
assert "Login" in self.driver.title
def test_open_welcome_page(self):
"""fast selenium test for local testing"""
self.driver.set_page_load_timeout(20)
self.driver.get(self.h5_client_url)
assert "Welcome" in self.driver.title
def test_selenium_fail(self):
"""quick test of selenium failure for local testing"""
self.driver.set_page_load_timeout(20)
self.driver.get(self.h5_client_url)
assert "NotInHere" in self.driver.title
我需要所有这些参数都由外部python提供的测试参数框架提供。我需要知道这个框架应该如何获得参数的名称,以及如何使用这些参数运行这些测试。根据您在评论中的回答,数据每周都会更改 因此,我建议传入一个参数,即指定其余信息的文件路径 使用您在其他地方已经使用的任何解析机制—XML、Json,无论什么—或者使用简单的配置文件读取器
创建一个会话范围为的fixture,要么给它一些合理的默认值,要么在没有有效的参数文件的情况下让它严重失败。请提供一个具体的例子,说明您面临的问题参数是真正可变的,还是仅仅是一组配置,如开发服务器、qa服务器、,prod server?@Austin Hastings每周都会更换: