0

I am wondering if it is possible to run a test suite like this way:

suite1 = suite_loader.loadTestsFromTestCase(test_gtm_{}.{}TagManager)
suite2 = suite_loader.loadTestsFromTestCase(test_links_{}.{}Links)

So the specific test would run based on the user input.

Is it possible?

Rea Krakover
  • 113
  • 2
  • 13

1 Answers1

0

The solution is in general in python to run functions/tests as strings/vars.

Answer from - Calling a function of a module by using its name (a string)

from foo import bar

module = __import__('foo')
file = getattr(module, 'test_{}'.format(some_var))
run = getattr(file, '{}'.format(some_other_var))

And then this will work:

suite1 = suite_loader.loadTestsFromTestCase(run)
Rea Krakover
  • 113
  • 2
  • 13