سؤال

I'm creating a unittest- and Selenium-based test suite for a web application. It is reachable by several hostnames, e.g. implying different languages; but of course I want to be able to test e.g. my development instances as well without changing the code (and without fiddling with the hosts file which doesn't work for me anymore, because of network security considerations, I suppose).

Thus, I'd like to be able to specify the hostname by commandline arguments.

The test runner does argument parsing itself, e.g. for chosing the tests to execute. What is the recommended method to handle this situation?

هل كانت مفيدة؟

المحلول

The solution I came up with finally is:

  • Have a module for the tests which fixes the global data, including the hostname, and provides my TestCase class (I added an assertLoadsOk method to simply check for the HTTP status code).
  • This module does commandline processing as well:
    • It checks for its own options
    • and removes them from the argument vector (sys.argv).
    • When finding an "unknown" option, stop processing the options, and leave the rest to the testrunner.
  • The commandline processing happens on import, before initializing my TestCase class.

It works well for me ...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top