選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

running-tests.rst 3.8KB

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