2016-04-06 9 views
2

私はxUnitスタイルのテストのようにそれぞれのシナリオに対して別々のケースを作る必要はないので、テストシナリオをパラメタライズしようとしています。pytestは、私が1つを使用していないときにフィクスチャが見つかりません

私は自分自身のユースケースのために複製しようとしているpytestの例です。

from datetime import datetime, timedelta 

testdata = [ 
    (datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)), 
    (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)), 
] 


@pytest.mark.parametrize("a,b,expected", testdata) 
def test_timedistance_v0(a, b, expected): 
    diff = a - b 
    assert diff == expected 

上記はうまく動作しますが、以下に示すように私の使用のために修正しようとしたとき。私は、 "ダンプ"フィクスチャが見つからないというエラーが表示されます。私は何が起こっているのか分からない。これはpytestを使った初めてのことなので、何かが得られないかもしれません。

dump1 = load_dump(pathtodump1,pathtodump2) # load_dump can take multiple params 
dump2 = load_dump(pathtodump3) 

scenarios = [(dump1,{'prod_str':None}), 
      (dump2,{'prod_str':"123"})] 

@pytest.mark.paramaterize("dump,expected_meta", scenarios) 
def test_metadump_profiles(dump, expected_meta): 
     meta = dump.meta 
     assert meta.prod_str == expected_meta['prod_str'] 

これはpytestからのエラーです。また、テストを実行しないでデバッグしたとき、それはパラメタリゼーションデコレータのどこかで失敗することにも言及する必要があります。

========================================================================= ERRORS ========================================================================== 
________________________________________________________ ERROR at setup of test_metadump_profiles _________________________________________________________ 
file /x/x/x-x/x/x/x/x/x/x/test_x.py, line 81 
    @pytest.mark.paramaterize("dump,expect_meta", scenarios) 
    def test_metadump_profiles(dump, expect_meta): 
     fixture 'dump' not found 
     available fixtures: capfd, capsys, recwarn, tmpdir_factory, tmpdir, monkeypatch, pytestconfig, record_xml_property, cache 
     use 'py.test --fixtures [testpath]' for help on them. 


. 

答えて

5
@pytest.mark.paramaterize 

これは無効であり、pytestは意味をなさないあいまいなエラーがスローされます。これはスペルミスのために発生します...

@pytest.mark.parametrize 

は有効なスペルです。ばかげたバグ私は私の髪を引っ張った。 github issue on this topic for more info.

関連する問題