2016-08-23 15 views
1

pytestで分散テストを実行してコマンドライン引数を見つけることはできますか?@ pytest.mark.parametrizeのPytestコマンドライン引数

py.test -n 16 tests/tests_*****.py --env="TestEnvironemnt" --html=XYZ/Reports.html 

os.sys.argvは私pytestコードに

+0

で値を取得します/docs.pytest.org/en/latest/example/simple.html#pass-different-values-to-a-test-function-depending-on-command-line-options)答えてください。 –

+0

上記のリンクは私のために働いていません。ただし、次のとおりです:http://docs.pytest.org/ja/latest/example/simple.html –

答えて

0

を実行していた場合の質問は非常に明確ではありませんが、私はあなたが「オプションを追加したいと仮定し、私のコードで「-c」として与えています - -env "を読み込み、その値を読み込みます。それを行うには

方法は次のとおりです。

  1. は、(それがまだ存在しない場合)、プロジェクト内のファイルconftest.pyを作成し、--env
オプションを追加します
#conftest.py 
def pytest_addoption(parser): 
    parser.addoption('--env', action="store", dest="env", default="", 
    help="Define name of test environment") 

テスト機能では
  • [オプション]オプション--env

  • #conftest.py 
    @pytest.fixture 
    def env_name(request): 
        return request.config.getoption('env') 
    

    の値で固定具 env_nameを割り当て
  • 、フィクスチャenv_nameを使用して、オプションの値を取得します。 /: 定義されていない場合、私は私が正しくあなたの質問を理解してかどうかわからないんだけど、(HTTP [この例]ない代わりに、固定具要求を使用してrequest.config.getoption('env')

  • #test.py 
    def test1(env_name): 
        print("Test Environment is: {}".format(env_name)) 
    
    関連する問題