You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

running-tests.rst 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ==========
  2. Test suite
  3. ==========
  4. Running tests
  5. -------------
  6. Oscar uses a nose_ testrunner which can be invoked using::
  7. $ ./runtests.py
  8. .. _nose: http://nose.readthedocs.org/en/latest/
  9. To run a subset of tests, you can use filesystem or module paths. These two
  10. commands will run the same set of tests::
  11. $ ./runtests.py tests/unit/offer/availability_tests.py
  12. $ ./runtests.py tests.unit.offer.availability_tests
  13. To run an individual test class, use one of::
  14. $ ./runtests.py tests/unit/offer/availability_tests.py:TestAPerUserConditionalOffer
  15. $ ./runtests.py tests.unit.offer.availability_tests:TestAPerUserConditionalOffer
  16. (Note the ':'.)
  17. To run an individual test, use one of::
  18. $ ./runtests.py tests/unit/offer/availability_tests.py:TestAPerUserConditionalOffer.test_is_available_with_no_applications
  19. $ ./runtests.py tests.unit.offer.availability_tests:TestAPerUserConditionalOffer.test_is_available_with_no_applications
  20. To check if the number of queries changes::
  21. $ ./runtests.py --with-querycount
  22. Please note that ``--with-querycount`` sets ``DEBUG = True``, which might affect
  23. test outcomes. Total query count gives a quick indication. Diff'ing the outputs
  24. is recommended for further analysis.
  25. Testing against different setups
  26. --------------------------------
  27. To run all tests against multiple versions of Django and Python, use detox_::
  28. $ detox
  29. You need to have all Python interpreters to test against installed on your
  30. system. All other requirements are downloaded automatically.
  31. detox_ is a wrapper around tox_, creating the environments and running the tests
  32. in parallel. This greatly speeds up the process.
  33. .. _tox: http://tox.readthedocs.org/en/latest/
  34. .. _detox: https://pypi.python.org/pypi/detox
  35. Kinds of tests
  36. --------------
  37. Tests are split into 3 folders:
  38. * unit - These are for tests that exercise a single unit of functionality, like
  39. a single model. Ideally, these should not write to the database at all - all
  40. operations should be in memory.
  41. * integration - These are for tests that exercise a collection or chain of
  42. units, like testing a template tag.
  43. * functional - These should be as close to "end-to-end" as possible. Most of
  44. these tests should use WebTest to simulate the behaviour of a user browsing
  45. the site.
  46. Naming tests
  47. ------------
  48. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  49. practice to name your test cases and methods so that the spec output reads well.
  50. For example::
  51. $ ./runtests.py tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount
  52. nosetests --verbosity 1 tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount -s -x --with-spec
  53. Creating test database for alias 'default'...
  54. Absolute discount
  55. - consumes all lines for multi item basket cheaper than threshold
  56. - consumes all products for heterogeneous basket
  57. - consumes correct quantity for multi item basket more expensive than threshold
  58. - correctly discounts line
  59. - discount is applied to lines
  60. - gives correct discount for multi item basket cheaper than threshold
  61. - gives correct discount for multi item basket more expensive than threshold
  62. - gives correct discount for multi item basket with max affected items set
  63. - gives correct discount for single item basket cheaper than threshold
  64. - gives correct discount for single item basket equal to threshold
  65. - gives correct discount for single item basket more expensive than threshold
  66. - gives correct discounts when applied multiple times
  67. - gives correct discounts when applied multiple times with condition
  68. - gives no discount for a non discountable product
  69. - gives no discount for an empty basket
  70. ----------------------------------------------------------------------
  71. Ran 15 tests in 0.295s
  72. .. _spec: https://github.com/bitprophet/spec