Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

running-tests.rst 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ==========
  2. Test suite
  3. ==========
  4. Testing requirements
  5. --------------------
  6. You'll need:
  7. - A running SQL server (PostgreSQL, or SQLite with `--sqlite` params)
  8. - python3.5 or python3.6
  9. Running tests
  10. -------------
  11. Oscar uses pytest_ to run the tests.
  12. .. _pytest: http://pytest.org/latest/
  13. The fast way is::
  14. $ make test
  15. This will create a virtualenv in `venv`, install the test dependencies and run py.test.
  16. Details
  17. ~~~~~~~
  18. First we create a virtualenv, install the required dependencies and activate it::
  19. $ make venv
  20. $ source venv/bin/activate
  21. Then we invoke pytest using ::
  22. $ py.test
  23. You can run a subset of the tests by passing a path:
  24. $ py.test tests/integration/offer/test_availability.py
  25. To run an individual test class, use::
  26. $ py.test tests/integration/offer/test_availability.py::TestASuspendedOffer
  27. (Note the '::'.)
  28. To run an individual test, use::
  29. $ py.test tests/integration/offer/test_availability.py::TestASuspendedOffer::test_is_unavailable
  30. You can also run tests which match an expression via::
  31. $ py.test tests/integration/offer/test_availability.py -k is_unavailable
  32. Testing against different setups
  33. --------------------------------
  34. To run all tests against multiple versions of Django and Python, use tox_::
  35. $ tox
  36. You need to have all Python interpreters to test against installed on your
  37. system. All other requirements are downloaded automatically.
  38. To speed up the process, you may want to use `tox parallel mode`_.
  39. .. _tox: https://tox.readthedocs.io/en/latest/
  40. .. _tox parallel mode: https://tox.readthedocs.io/en/latest/example/basic.html#parallel-mode
  41. Kinds of tests
  42. --------------
  43. Tests are split into 3 folders:
  44. * integration - These are for tests that exercise a collection or chain of
  45. units, like testing a template tag.
  46. * functional - These should be as close to "end-to-end" as possible. Most of
  47. these tests should use WebTest to simulate the behaviour of a user browsing
  48. the site.
  49. Naming tests
  50. ------------
  51. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  52. practice to name your test cases and methods so that the spec output reads well.
  53. For example::
  54. $ py.test tests/integration/catalogue/test_product.py --spec
  55. ============================ test session starts =============================
  56. platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
  57. rootdir: /Users/sasha0/projects/djangooscar, inifile: setup.cfg
  58. plugins: xdist-1.15.0, warnings-0.2.0, spec-1.1.0, django-3.1.2, cov-2.4.0
  59. collected 15 items
  60. tests/integration/catalogue/test_product.py::ProductCreationTests
  61. [PASS] Allow two products without upc
  62. [PASS] Create products with attributes
  63. [PASS] None upc is represented as empty string
  64. [PASS] Upc uniqueness enforced
  65. tests/integration/catalogue/test_product.py::TopLevelProductTests
  66. [PASS] Top level products are part of browsable set
  67. [PASS] Top level products must have product class
  68. [PASS] Top level products must have titles
  69. tests/integration/catalogue/test_product.py::ChildProductTests
  70. [PASS] Child products are not part of browsable set
  71. [PASS] Child products dont need a product class
  72. [PASS] Child products dont need titles
  73. [PASS] Child products inherit fields
  74. tests/integration/catalogue/test_product.py::TestAChildProduct
  75. [PASS] Delegates requires shipping logic
  76. tests/integration/catalogue/test_product.py::ProductAttributeCreationTests
  77. [PASS] Entity attributes
  78. [PASS] Validating option attribute
  79. tests/integration/catalogue/test_product.py::ProductRecommendationTests
  80. [PASS] Recommended products ordering
  81. ========================= 15 passed in 15.39 seconds =========================
  82. .. _spec: https://pypi.python.org/pypi/pytest-spec