py.test를 사용하여 기능 테스트 프레임 워크를 작성하므로 정확한 테스트를 실행할 수 있도록 지정해야합니다. 나는 동적 테스트 콜렉션의 장점을 이해하지만, 먼저 테스트 환경 건강 검사를 실행하고 난 후 내 회귀 테스트를 실행할 수 있기를 원합니다. 분류가 다른 목적으로 사용되는 이러한 세트의 테스트를 배제하지 않는다는 것을 의미합니다.py.test로 테스트 스위트 (임의의 테스트 컬렉션) 실행
테스트 스위트는 Jenkins 빌드 프로젝트와 연결됩니다. osx, python 2.7.3, py.test 2.3.4를 사용하고 있습니다. 나는이 제품군에 대한 명령 줄에서 다음 실행하면
# suite_regression.py
import unittest, pytest
import functionaltests.sample_unittest as sample_unittest
# set up the imported tests
suite_sample_unittest = sample_unittest.suite()
# create this test suite
suite = unittest.TestSuite()
suite.addTest(suite_sample_unittest)
# run the suite
unittest.TextTestRunner(verbosity=2).run(suite)
:
그래서 나는 다음과 같은 테스트 케이스가 있습니다
# sample_unittest.py
import unittest, pytest
class TestClass(unittest.TestCase):
def setUp(self):
self.testdata = ['apple', 'pear', 'berry']
def test_first(self):
assert 'apple' in self.testdata
def test_second(self):
assert 'pear' in self.testdata
def tearDown(self):
self.testdata = []
def suite():
suite = unittest.TestSuite()
suite.addTest(TestClass('test_first'))
return suite
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
를 그리고 난 이런 테스트 스위트를 가지고 test_first가 실행됩니다 (그러나 py.test가 제공 할 추가 정보를 얻지 못함).
python functionaltests/suite_regressi on.py -v
나는 제품군에 대해 다음을 실행하면, 0 테스트를 수집 : 나는 실행하면 다음과 같은
py.test functionaltests/suite_regression.py
을 테스트 케이스에 대해 test_first 및 test_second가 실행됩니다.
py.test functionaltests/sample_unittest.py -v
어떻게 py.test 키워드를 사용하면 테스트를 스위트로 구성하는 데 도움이되는지 알 수 없습니다. 테스트 케이스를 폴더 구조에 배치하고 폴더 옵션을 사용하여 py.test를 실행하면 기능 영역별로 테스트를 구성 할 수 없습니다.
그래서 내 질문 :
- 는 재사용 가능한 형식으로 시험의 임의의 그룹을 지정하는 py.test 메커니즘이 있습니까?
- py.test에서 unittest.TestSuite를 사용할 방법이 있습니까?
편집 : 그래서 나는 임의의 레이블이 나에게 플래그 테스트 기능 및 시험 방법을 할 수있는 py.test 마커를 시도하고 런타임에 해당 레이블에 대한 필터링합니다.
# conftest.py
import pytest
# set up custom markers
regression = pytest.mark.NAME
health = pytest.mark.NAME
그리고 내 업데이트 된 테스트 케이스 :
# sample_unittest.py
import unittest, pytest
class TestClass(unittest.TestCase):
def setUp(self):
self.testdata = ['apple', 'pear', 'berry']
@pytest.mark.healthcheck
@pytest.mark.regression
def test_first(self):
assert 'apple' in self.testdata
@pytest.mark.regression
def test_second(self):
assert 'pear' in self.testdata
def tearDown(self):
self.testdata = []
def suite():
suite = unittest.TestSuite()
suite.addTest(TestClass('test_first'))
return suite
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
그래서 다음 명령 수집을 실행은 test_first 실행 :
py.test functionaltests/sample_unittest합니다.평 -v -m 상태 검사 그리고이 수집 test_first 실행 test_second
: 그래서 뒤로
py.test functionaltests/sample_unittest.py -v -m 회귀
을 내 질문 : 마커는 부분적인 해결책이지만 수집 된 마킹 된 테스트의 실행을 제어 할 수있는 방법이 아직 없습니다.
* "수집 된 표시된 테스트의 실행을 제어 할 수있는 방법이 없습니다."* 무슨 뜻입니까? 순서? –
예, 임의의 순서에 따라 실행을 제어하고 수집 된 테스트의 기본 순서에 의존하지 않습니다. – sophe