testing.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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
  31. ~~~~~~~~~~~~~~~~~~~~
  32. If you’d like to run the tests on a specific environment only, say Python 2.7,
  33. use a command like this: ``tox -e py27``. Alternativley, to use your default
  34. python, you can also run the test command directly ``python setup.py test``.
  35. Select infrastructure
  36. ~~~~~~~~~~~~~~~~~~~~~
  37. You can also run the tests on a specific cloud only. To do so, export an
  38. environment variable ``CB_TEST_PROVIDER`` and specify the desired provider
  39. name. The available provider names are listed in the `ProviderList`_ class
  40. (e.g., ``aws`` or ``openstack``). Then, run the ``tox`` command.
  41. Using a mock provider
  42. ~~~~~~~~~~~~~~~~~~~~~
  43. Note that running the tests may create various cloud resources, for which you
  44. may incur costs. For the AWS cloud, there is also a mock provider (`moto`_) that
  45. will simulate AWS resources. It is used by default when running the test suite.
  46. You can toggle the use of mock providers by setting an environment variable:
  47. ``CB_USE_MOCK_PROVIDERS`` to ``Yes`` or ``No``.
  48. .. _design goals: https://github.com/gvlproject/cloudbridge/
  49. blob/master/README.rst
  50. .. _tox: https://tox.readthedocs.org/en/latest/
  51. .. _ProviderList: https://github.com/gvlproject/cloudbridge/blob/master/
  52. cloudbridge/cloud/factory.py#L15
  53. .. _moto: https://github.com/spulec/moto