내 자동화 프레임 워크는 픽스처 대신 pytest setup/teardown 유형의 테스트를 사용합니다. 또한 여러 클래스의 레벨이 있습니다pytest : 설정/티어 다운 방법 중 매개 변수 값 가져 오기
BaseClass
을 - 높은, 모든 테스트가 inhriet에서 그것을
FeatureClass
- 그것은
TestClass
에서 매체, 프로그램과 관련된 모든 테스트는 상속 기능 - 실제 시험을 개최
편집, 예제를 위해서, 나는
I가 원하는 DB는 간단한 인쇄 호출 변경 모든 setup/teardowns에 DB 보고서를 추가하십시오. 즉, 일반 BaseClass
setup_method
이 테스트 용 DB 항목을 만들고 teardown_method
이 항목을 결과로 변경하려고합니다. 나는 시도했지만 런타임 중에 실행중인 테스트의 값을 메소드에서 가져올 수 없다. 심지어 가능할까요? 그렇지 않다면 어떻게해야합니까?
샘플 : (base.py)에 너무
class TestClass(my_feature.MyFeature):
@pytest.mark.parametrize("fragment_length", [1,5,10])
def test_my_first_test(self):
# do stuff that is changed based on fragment_length
assert verify_stuff(fragment_length)
(test_my_feature.py)에
class MyFeature(base.Base):
def setup_method(self, method):
# enable this feature in program
return True
어떻게 수 (my_feature.py)에
class Base(object):
test_number = 0
def setup_method(self, method):
Base.test_number += 1
self.logger.info(color.Blue("STARTING TEST"))
self.logger.info(color.Blue("Current Test: {}".format(method.__name__)))
self.logger.info(color.Blue("Test Number: {}".format(self.test_number)))
# --->here i'd like to do something with the actual test parameters<---
self.logger.info("print parameters here")
def teardown_method(self, method):
self.logger.info(color.Blue("Current Test: {}".format(method.__name__)))
self.logger.info(color.Blue("Test Number: {}".format(self.test_number)))
self.logger.info(color.Blue("END OF TEST"))
테스트 프레임 워크의 기본 상위 클래스 인 setup_method에서 매개 변수를 가져 오겠습니까?
당신이'unittest.TestCase'를 사용하고 있습니까 : 여기
는 실행입니까? 그런 다음'setup '의 값을'self'로 설정하고 테스트에서 가져올 수 있습니다. 이 질문에 대답하기 위해 샘플 코드와 같은 세부 정보가 필요합니다. – Arunmozhi@Arunmozhi 몇 가지 기본 코드를 추가했습니다. 내가하려고하는 것을 분명히 할 수 있기를 바랍니다. –