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)를 참조하십시오. –