Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

running-tests.rst 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 and install the required dependencies::
  19. $ virtualenv venv
  20. $ source venv/bin/activate
  21. $ pip install -e .[test]
  22. Then we invoke pytest 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 detox_::
  36. $ detox
  37. You need to have all Python interpreters to test against installed on your
  38. system. All other requirements are downloaded automatically.
  39. detox_ is a wrapper around tox_, creating the environments and running the tests
  40. in parallel. This greatly speeds up the process.
  41. .. _tox: https://tox.readthedocs.io/en/latest/
  42. .. _detox: https://pypi.python.org/pypi/detox
  43. Kinds of tests
  44. --------------
  45. Tests are split into 3 folders:
  46. * integration - These are for tests that exercise a collection or chain of
  47. units, like testing a template tag.
  48. * functional - These should be as close to "end-to-end" as possible. Most of
  49. these tests should use WebTest to simulate the behaviour of a user browsing
  50. the site.
  51. Naming tests
  52. ------------
  53. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  54. practice to name your test cases and methods so that the spec output reads well.
  55. For example::
  56. $ py.test tests/integration/catalogue/test_product.py --spec
  57. ============================ test session starts =============================
  58. platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
  59. rootdir: /Users/sasha0/projects/djangooscar, inifile: setup.cfg
  60. plugins: xdist-1.15.0, warnings-0.2.0, spec-1.1.0, django-3.1.2, cov-2.4.0
  61. collected 15 items
  62. tests/integration/catalogue/test_product.py::ProductCreationTests
  63. [PASS] Allow two products without upc
  64. [PASS] Create products with attributes
  65. [PASS] None upc is represented as empty string
  66. [PASS] Upc uniqueness enforced
  67. tests/integration/catalogue/test_product.py::TopLevelProductTests
  68. [PASS] Top level products are part of browsable set
  69. [PASS] Top level products must have product class
  70. [PASS] Top level products must have titles
  71. tests/integration/catalogue/test_product.py::ChildProductTests
  72. [PASS] Child products are not part of browsable set
  73. [PASS] Child products dont need a product class
  74. [PASS] Child products dont need titles
  75. [PASS] Child products inherit fields
  76. tests/integration/catalogue/test_product.py::TestAChildProduct
  77. [PASS] Delegates requires shipping logic
  78. tests/integration/catalogue/test_product.py::ProductAttributeCreationTests
  79. [PASS] Entity attributes
  80. [PASS] Validating option attribute
  81. tests/integration/catalogue/test_product.py::ProductRecommendationTests
  82. [PASS] Recommended products ordering
  83. ========================= 15 passed in 15.39 seconds =========================
  84. .. _spec: https://pypi.python.org/pypi/pytest-spec