File: getting-started.rst

package info (click to toggle)
python-sure 2.0.1%2Bgit.2023.02.06.3aef950b7c-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: python: 3,517; makefile: 255; sh: 12
file content (72 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Getting Started
===============

Installing
----------

It is available in PyPi, so you can install through pip:

.. code:: bash

    pip install sure
    pip3 install sure

Activating
----------

Sure is activated upon importing it, unless the environment variable
``SURE_DISABLE_NEW_SYNTAX`` is set to any non-falsy value. (You could
just use ``true``)

For test code cleaningness it's recommended to import sure only once in
the ``__init__.py`` of your root test package.

Here is an example:

.. code:: bash

    mymodule.py
    tests/
    tests/__init__.py  # this is our guy
    tests/unit/__init__.py
    tests/unit/test_mymodule_unit1.py
    tests/functional/__init__.py
    tests/functional/test_mymodule_functionality.py

That is unless, of course, you want to explicitly import the assertion
helpers from sure in every module.

Python version compatibility
============================

Sure is `continuously tested
against <https://travis-ci.org/gabrielfalcao/sure/>`__ python versions
2.7, 3.3, 3.4 and 3.5, but its assertion API is most likely to work anywhere.
The only real big difference of sure in cpython and even other
implementations such as `PyPy <http://pypy.org/>`__ is that the
`monkey-patching <how-it-works.md#monkey-patching>`__ only happens in
CPython.

You can always get around beautifully with ``expect``:

.. code:: python

    from sure import expect

    expect("this".replace("is", "at")).to.equal("that")

where in cpython you could do:

.. code:: python

    "this".replace("is", "at").should.equal("that")

Disabling the monkey patching
=============================

Just export the ``SURE_DISABLE_NEW_SYNTAX`` environment variable before
running your tests.

.. code:: console

    export SURE_DISABLE_NEW_SYNTAX=true