File: index.rst

package info (click to toggle)
python-time-machine 2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: python: 1,826; ansic: 639; makefile: 14
file content (45 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download
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
time-machine documentation
==========================

*Travel through time in your tests.*

A quick example:

.. code-block:: python

    import datetime as dt
    from zoneinfo import ZoneInfo
    import time_machine

    hill_valley_tz = ZoneInfo("America/Los_Angeles")


    @time_machine.travel(dt.datetime(1985, 10, 26, 1, 24, tzinfo=hill_valley_tz))
    def test_delorean():
        assert dt.date.today().isoformat() == "1985-10-26"

For a bit of background, see `the introductory blog post <https://adamj.eu/tech/2020/06/03/introducing-time-machine/>`__ and `the benchmark blog post <https://adamj.eu/tech/2021/02/19/freezegun-versus-time-machine/>`__.

----

**Testing a Django project?**
Check out my book `Speed Up Your Django Tests <https://adamchainz.gumroad.com/l/suydt>`__ which covers loads of ways to write faster, more accurate tests.
I created time-machine whilst writing the book.

----

time-machine is a tool for mocking the time in tests.

To get started, see :doc:`installation`, :doc:`usage`, and :doc:`pytest_plugin`.
If you’re coming from freezegun or libfaketime, see :doc:`comparison` and :doc:`migration`.

.. toctree::
   :maxdepth: 1
   :caption: Contents:

   installation
   usage
   pytest_plugin
   changelog
   comparison
   migration