Files
galaxy/test/functional/test_toolbox_pytest.py
T
mvdbeek 2b275b7df0 Start counting test numbers at 1 and use _test_n
That allows for nicer select syntax like
````
pytest test/functional/test_toolbox_pytest.py -k '(random_lines1 or Cut1) and _test_1'
```
2018-08-16 19:14:33 +02:00

60 lines
1.7 KiB
Python

import os
import sys
galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir + '/' + os.path.pardir))
sys.path[1:1] = [os.path.join(galaxy_root, "lib"), os.path.join(galaxy_root, "test")]
import pytest
from base import driver_util
TEST_PREFIX = 'TestForTool_'
class DefaultGalaxyTestDriver(driver_util.GalaxyTestDriver):
"""Default Galaxy-style nose test driver.
Just populate non-shed tool tests and run tests. Works
for tool tests, regular twill tests, and API testing.
"""
def build_tests(self):
"""Build framework tool test methods."""
return self.build_tool_tests(return_test_classes=True)
def galaxy_driver():
driver = DefaultGalaxyTestDriver()
driver.setup()
return driver
@pytest.fixture(scope='module')
def driver(request):
request.addfinalizer(DRIVER.tear_down)
return DRIVER
def cases():
# We setup a global driver, so that the driver fixture can tear down the driver
# Ideally `galaxy_driver` or `cases` would be fixtures and clean up after the yield,
# but that's not compatible with the use use of pytest.mark.parametrize
global DRIVER
DRIVER = galaxy_driver()
tests = DRIVER.build_tests()
for test_name, test_class in tests.items():
if test_name.startswith(TEST_PREFIX):
test_class.runTest = lambda : None
test_instance = test_class()
for index in range(test_instance.test_count):
yield (test_name[len(TEST_PREFIX):] + "_test_%d" % (index + 1), test_instance, index)
def idfn(val):
return val[0]
@pytest.mark.parametrize("testcases", cases(), ids=idfn)
def test_tool(testcases, driver):
test = testcases[1]
test.do_it(test_index=testcases[2])