I use py.test to create a functional test environment, so I need to specify the exact tests that need to be run. I understand the beauty of a dynamic collection of tests, but I want to first run a test of the health of the test environment, and then run my regression tests; that categorization does not exclude that the tests in these sets are used for other purposes.
The test suite will be tied to Jenkins build projects. I am using osx, python 2.7.3, py.test 2.3.4.
So I have a test case:
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())
And I have a test suite like this:
import unittest, pytest
import functionaltests.sample_unittest as sample_unittest
suite_sample_unittest = sample_unittest.suite()
suite = unittest.TestSuite()
suite.addTest(suite_sample_unittest)
unittest.TextTestRunner(verbosity=2).run(suite)
If I run the following from the command line for the package, test_first launches (but I do not get the additional information py.test can provide):
python/suite_regression.py -v
, 0 :
py.test functiontests/suite_regression.py
, test_first test_second:
py.test functiontests/sample_unittest.py -v
, py.test . py.test .
, :
- py.test ?
- unittest.TestSuite py.test?
EDIT:
py.test, , .
import pytest
regression = pytest.mark.NAME
health = pytest.mark.NAME
:
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 functiontests/sample_unittest.py -v -m healthcheck
test_first test_second:
py.test functiontests/sample_unittest.py -v -m
, : - , .