2017-05-18 9 views
0

私は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 

です。そして、私はこのフレームワークがどのようにパラメータの名前を得るべきか、これらのパラメータでこれらのテストを実行する方法を知る必要があります。

+0

あなたが直面している問題の具体的な例を提供してください – e4c5

+0

本当に可変であるか、それとも実際にはdevサーバ、qaサーバ、prodサーバのような構成の集合ですか? –

+0

@Austin Hastings毎週変更されています:) –

答えて

1

コメントの回答があれば、データは毎週変更されます。

私は単一のパラメータ、あなたの情報の残りを指定するファイルへのパスを渡すことをお勧めしたいと思います。

XML、Json、その他のもので既に使用している構文解析メカニズムを使用してください。設定ファイルリーダーのような単純なものを使用してください。

セッションスコープ(thisなど)を使用してフィクスチャを作成し、適切なパラメータファイルを取得できない場合は妥当なデフォルト値を与えてください。

関連する問題