私はpytestフレームワークが初めてで、私のpytestsが他のスクリプトからパラメータを受け取る標準的なアプローチがあるのだろうかと思います。 (このコマンドは、他のいくつかのスクリプトによって実行される)python pytest - 外部からテストパラメータを受け取ります。
@pytest.fixture
def param(request):
device = request.config.getoption("--parameter")
if parameter == 'A':
return value_a
else:
return default_value
とコマンドpy.test --parameter=value_a
で私のテストを実行している
しかし、私のテストでは、多くのパラメータを必要とする場合、私は、最も一般的な方法は次のようになり@pytest.fixture
を書くことだと思います1つの長いコマンドである例えば10を挙げることができる。だから私はそのような状況で標準的なアプローチは何かを尋ねている - 私はそれらからパラメータを取るために、いくつかの種類のxmlファイルまたはシリアル化された辞書とパラメータを提供するかどうかを調べる。
私のテストに提供するパラメータの種類は、私の他のスクリプトがどのように知っているのか - 私のconftest.pyには、test_parameters設定ファイルやハードコーディングされたデータがあるか、それらのテストの署名をfrom 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
です。そして、私はこのフレームワークがどのようにパラメータの名前を得るべきか、これらのパラメータでこれらのテストを実行する方法を知る必要があります。
あなたが直面している問題の具体的な例を提供してください – e4c5
本当に可変であるか、それとも実際にはdevサーバ、qaサーバ、prodサーバのような構成の集合ですか? –
@Austin Hastings毎週変更されています:) –