| 1 |
Getting Started |
| 2 |
=============== |
| 3 |
|
| 4 |
Installing |
| 5 |
---------- |
| 6 |
|
| 7 |
It is available in PyPi, so you can install through pip: |
| 8 |
|
| 9 |
.. code:: bash |
| 10 |
|
| 11 |
pip install sure |
| 12 |
pip3 install sure |
| 13 |
|
| 14 |
Activating |
| 15 |
---------- |
| 16 |
|
| 17 |
Sure is activated upon importing it, unless the environment variable |
| 18 |
``SURE_DISABLE_NEW_SYNTAX`` is set to any non-falsy value. (You could |
| 19 |
just use ``true``) |
| 20 |
|
| 21 |
For test code cleaningness it's recommended to import sure only once in |
| 22 |
the ``__init__.py`` of your root test package. |
| 23 |
|
| 24 |
Here is an example: |
| 25 |
|
| 26 |
.. code:: bash |
| 27 |
|
| 28 |
mymodule.py |
| 29 |
tests/ |
| 30 |
tests/__init__.py # this is our guy |
| 31 |
tests/unit/__init__.py |
| 32 |
tests/unit/test_mymodule_unit1.py |
| 33 |
tests/functional/__init__.py |
| 34 |
tests/functional/test_mymodule_functionality.py |
| 35 |
|
| 36 |
That is unless, of course, you want to explicitly import the assertion |
| 37 |
helpers from sure in every module. |
| 38 |
|
| 39 |
Python version compatibility |
| 40 |
============================ |
| 41 |
|
| 42 |
Sure is `continuously tested |
| 43 |
against <https://travis-ci.org/gabrielfalcao/sure/>`__ python versions |
| 44 |
2.7, 3.3, 3.4 and 3.5, but its assertion API is most likely to work anywhere. |
| 45 |
The only real big difference of sure in cpython and even other |
| 46 |
implementations such as `PyPy <http://pypy.org/>`__ is that the |
| 47 |
`monkey-patching <how-it-works.md#monkey-patching>`__ only happens in |
| 48 |
CPython. |
| 49 |
|
| 50 |
You can always get around beautifully with ``expect``: |
| 51 |
|
| 52 |
.. code:: python |
| 53 |
|
| 54 |
from sure import expect |
| 55 |
|
| 56 |
expect("this".replace("is", "at")).to.equal("that") |
| 57 |
|
| 58 |
where in cpython you could do: |
| 59 |
|
| 60 |
.. code:: python |
| 61 |
|
| 62 |
"this".replace("is", "at").should.equal("that") |
| 63 |
|
| 64 |
Disabling the monkey patching |
| 65 |
============================= |
| 66 |
|
| 67 |
Just export the ``SURE_DISABLE_NEW_SYNTAX`` environment variable before |
| 68 |
running your tests. |
| 69 |
|
| 70 |
.. code:: console |
| 71 |
|
| 72 |
export SURE_DISABLE_NEW_SYNTAX=true |