testing.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Running tests
  2. =============
  3. In the spirit of the library's :doc:`design_goals`, the aim is to have thorough
  4. tests for the entire library. This page explains the testing philosophy and
  5. shows how to run the tests locally.
  6. Testing philosophy
  7. ------------------
  8. Our testing goals are to:
  9. 1. Write one set of tests that all provider implementations must pass.
  10. 2. Make that set of tests a 'conformance' test suite, which validates that each
  11. implementation correctly implements the CloudBridge specification.
  12. 3. Make the test suite comprehensive enough that a provider which passes all
  13. the tests can be used safely by an application with no additional testing.
  14. In other words, the CloudBridge specification and accompanying test suite
  15. must be comprehensive enough that no provider specific workarounds, code or
  16. testing is required.
  17. 4. For development, mock providers may be used to speed up the feedback cycle,
  18. but providers must also pass the full suite of tests when run against actual
  19. cloud infrastructure to ensure that we are not testing against an idealised
  20. or imagined environment.
  21. 5. Aim for 100% code coverage.
  22. Running tests
  23. -------------
  24. To run the test suite locally:
  25. 1. Install `tox`_ with :code:`pip install tox`
  26. 2. Export all environment variables listed in ``tox.ini`` (under ``passenv``)
  27. 3. Run ``tox`` command
  28. This will run all the tests for all the environments defined in file
  29. ``tox.ini``.
  30. Specific environment and infrastructure
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. If you’d like to run the tests on a specific environment only, say Python 2.7,
  33. against a specific infrastructure, say aws, use a command like this:
  34. ``tox -e py27-aws``. The available provider names are listed in the
  35. `ProviderList`_ class (e.g., ``aws`` or ``openstack``).
  36. Specific test cases
  37. ~~~~~~~~~~~~~~~~~~~~
  38. You can run a specific test case, as follows:
  39. ``tox -- -s test.test_cloud_factory.CloudFactoryTestCase``
  40. It can also be restricted to a particular environment as follows:
  41. ``tox -e "py27-aws" -- -s test.test_cloud_factory.CloudFactoryTestCase``
  42. Using unittest directly
  43. ~~~~~~~~~~~~~~~~~~~~~~~
  44. You can also run the tests against your active virtual environment directly
  45. with ``python setup.py test``. You will need to set the ``CB_TEST_PROVIDER``
  46. and ``CB_USE_MOCK_PROVIDERS`` environment variables prior to running the tests,
  47. or they will default to ``CB_TEST_PROVIDER=aws`` and
  48. ``CB_USE_MOCK_PROVIDERS=True``.
  49. You can also run a specific test case, as follows:
  50. ``python setup.py test -s test.test_cloud_factory.CloudFactoryTestCase``
  51. Using a mock provider
  52. ~~~~~~~~~~~~~~~~~~~~~
  53. Note that running the tests may create various cloud resources, for which you
  54. may incur costs. For the AWS cloud, there is also a mock provider (`moto`_) that
  55. will simulate AWS resources. It is used by default when running the test suite.
  56. You can toggle the use of mock providers by setting an environment variable:
  57. ``CB_USE_MOCK_PROVIDERS`` to ``Yes`` or ``No``.
  58. .. _design goals: https://github.com/CloudVE/cloudbridge/
  59. blob/master/README.rst
  60. .. _tox: https://tox.readthedocs.org/en/latest/
  61. .. _ProviderList: https://github.com/CloudVE/cloudbridge/blob/master/
  62. cloudbridge/cloud/factory.py#L15
  63. .. _moto: https://github.com/spulec/moto