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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ==========
  2. Test suite
  3. ==========
  4. Running tests
  5. -------------
  6. Oscar uses pytest_ to run the tests, which can be invoked using::
  7. $ ./runtests.py
  8. .. _pytest: http://pytest.org/latest/
  9. You can run a subset of the tests by passing a path:
  10. $ ./runtests.py tests/unit/offer/availability_tests.py
  11. To run an individual test class, use::
  12. $ ./runtests.py tests/unit/offer/availability_tests.py::TestASuspendedOffer
  13. (Note the '::'.)
  14. To run an individual test, use::
  15. $ ./runtests.py tests/unit/offer/availability_tests.py::TestASuspendedOffer::test_is_unavailable
  16. You can also run tests which match an expression via::
  17. $ ./runtests.py tests/unit/offer/availability_tests.py -k is_unavailable
  18. Testing against different setups
  19. --------------------------------
  20. To run all tests against multiple versions of Django and Python, use detox_::
  21. $ detox
  22. You need to have all Python interpreters to test against installed on your
  23. system. All other requirements are downloaded automatically.
  24. detox_ is a wrapper around tox_, creating the environments and running the tests
  25. in parallel. This greatly speeds up the process.
  26. .. _tox: https://tox.readthedocs.io/en/latest/
  27. .. _detox: https://pypi.python.org/pypi/detox
  28. Kinds of tests
  29. --------------
  30. Tests are split into 3 folders:
  31. * unit - These are for tests that exercise a single unit of functionality, like
  32. a single model. Ideally, these should not write to the database at all - all
  33. operations should be in memory.
  34. * integration - These are for tests that exercise a collection or chain of
  35. units, like testing a template tag.
  36. * functional - These should be as close to "end-to-end" as possible. Most of
  37. these tests should use WebTest to simulate the behaviour of a user browsing
  38. the site.
  39. Naming tests
  40. ------------
  41. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  42. practice to name your test cases and methods so that the spec output reads well.
  43. For example::
  44. $ py.test tests/integration/catalogue/product_tests.py --spec
  45. ============================== test session starts ==============================
  46. platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.7.0
  47. rootdir: /Users/mvantellingen/projects/django-oscar, inifile: setup.cfg
  48. plugins: cache, cov, django, spec, xdist
  49. collected 15 items
  50. tests/integration/catalogue/product_tests.py::ProductCreationTests
  51. [PASS] Allow two products without upc
  52. [PASS] Create products with attributes
  53. [PASS] None upc is represented as empty string
  54. [PASS] Upc uniqueness enforced
  55. tests/integration/catalogue/product_tests.py::TopLevelProductTests
  56. [PASS] Top level products are part of browsable set
  57. [PASS] Top level products must have product class
  58. [PASS] Top level products must have titles
  59. tests/integration/catalogue/product_tests.py::ChildProductTests
  60. [PASS] Child products are not part of browsable set
  61. [PASS] Child products dont need a product class
  62. [PASS] Child products dont need titles
  63. [PASS] Child products inherit fields
  64. [PASS] Have a minimum price
  65. tests/integration/catalogue/product_tests.py::TestAChildProduct
  66. [PASS] Delegates requires shipping logic
  67. tests/integration/catalogue/product_tests.py::ProductAttributeCreationTests
  68. [PASS] Entity attributes
  69. [PASS] Validating option attribute
  70. =========================== 15 passed in 1.64 seconds ===========================
  71. .. _spec: https://pypi.python.org/pypi/pytest-spec