Pytestでは、私は以前の結果を保存し、現在の/現在の結果を前の複数の繰り返しと比較する必要がある、次のことをやろうとしています。 私は、次の方法として行ってきた:私は毎回私のループ上記のように行うとpytestのグローバル変数
@pytest.mark.parametrize("iterations",[1,2,3,4,5]) ------> for 5 iterations
@pytest.mark.parametrize("clsObj",[(1,2,3)],indirect = True) ---> here clsObj is the instance. (clsObj.currentVal, here clsObj gets instantiated for every iteration and it is instance of **class func1**)
presentVal = 0
assert clsObj.currentVal > presrntVal
clsObj.currentVal = presentVal
presentValがのが0に割り当てる取得(それはローカル変数であるため、期待されます)。上記の代わりにpresentVal
をglobal presentVal
のようにグローバルに宣言しようとしましたが、私もpresentVal
を私のテストケースの上に初期化しましたが、うまくいきませんでした。
class func1():
def __init__(self):
pass
def currentVal(self):
cval = measure() ---------> function from where I get current values
return cval
は、誰かが事前にpytest
または他の最良の方法
おかげでグローバル変数を宣言する方法を提案することができます!
(「カウントのような些細なものになることができます"、range(5))'これがあなたに役立つかどうかは分かりません。 [this](https://stackoverflow.com/questions/42228895/how-to-parametrize-a-pytest-fixture)を参照してください。 –