您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

running-tests.rst 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ==========
  2. Test suite
  3. ==========
  4. Running tests
  5. -------------
  6. Oscar uses pytest_ to run the tests, which can be invoked using::
  7. $ py.test
  8. .. _pytest: http://pytest.org/latest/
  9. You can run a subset of the tests by passing a path:
  10. $ py.test tests/integration/offer/test_availability.py
  11. To run an individual test class, use::
  12. $ py.test tests/integration/offer/test_availability.py::TestASuspendedOffer
  13. (Note the '::'.)
  14. To run an individual test, use::
  15. $ py.test tests/integration/offer/test_availability.py::TestASuspendedOffer::test_is_unavailable
  16. You can also run tests which match an expression via::
  17. $ py.test tests/integration/offer/test_availability.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. * integration - These are for tests that exercise a collection or chain of
  32. units, like testing a template tag.
  33. * functional - These should be as close to "end-to-end" as possible. Most of
  34. these tests should use WebTest to simulate the behaviour of a user browsing
  35. the site.
  36. Naming tests
  37. ------------
  38. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  39. practice to name your test cases and methods so that the spec output reads well.
  40. For example::
  41. $ py.test tests/integration/catalogue/test_product.py --spec
  42. ============================ test session starts =============================
  43. platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
  44. rootdir: /Users/sasha0/projects/djangooscar, inifile: setup.cfg
  45. plugins: xdist-1.15.0, warnings-0.2.0, spec-1.1.0, django-3.1.2, cov-2.4.0
  46. collected 15 items
  47. tests/integration/catalogue/test_product.py::ProductCreationTests
  48. [PASS] Allow two products without upc
  49. [PASS] Create products with attributes
  50. [PASS] None upc is represented as empty string
  51. [PASS] Upc uniqueness enforced
  52. tests/integration/catalogue/test_product.py::TopLevelProductTests
  53. [PASS] Top level products are part of browsable set
  54. [PASS] Top level products must have product class
  55. [PASS] Top level products must have titles
  56. tests/integration/catalogue/test_product.py::ChildProductTests
  57. [PASS] Child products are not part of browsable set
  58. [PASS] Child products dont need a product class
  59. [PASS] Child products dont need titles
  60. [PASS] Child products inherit fields
  61. tests/integration/catalogue/test_product.py::TestAChildProduct
  62. [PASS] Delegates requires shipping logic
  63. tests/integration/catalogue/test_product.py::ProductAttributeCreationTests
  64. [PASS] Entity attributes
  65. [PASS] Validating option attribute
  66. tests/integration/catalogue/test_product.py::ProductRecommendationTests
  67. [PASS] Recommended products ordering
  68. ========================= 15 passed in 15.39 seconds =========================
  69. .. _spec: https://pypi.python.org/pypi/pytest-spec