Skip to main content

Pytest plugin for testing code using Redis

Project description

pytest-redislite

pytest-redislite -- Is a simple pytest plugin to help you test your projects using Redis.

Tests Status PYPI Version Python Versions

Features

  • Automatically starts/ends Redis for your tests using Redislite
  • Flash Redis Database between tests automatically

Requirements

  • python >= 3.7

Installation

pytest-redislite should be installed using pip:

pip install pytest-redislite

Usage

When installed the plugin provides the fixture: redis_url

    def test_code_with_redis(redis_url):
        from redis import Redis

        redis_client = Redis.from_url(redis_url)
        redis_client.set('key', 'value')
        assert redis_client.get('key', 'value')

When you are using the fixture Redis server will be started and finished after your tests.

Configuration

The plugins support pytest command line options:

  • --redis-path: Specify a path to Redis Database file
  • --redis-socket-path: Specify a path to Redis Socket

as well as pytest ini options:

  • redis_path: Specify a path to Redis Database file
  • redis_socket_path: Specify a path to Redis Socket

Fixtures

The plugin provides the fixtures:

  • redis_server (session scope) provides an instance of redislite.Redis. The fixture manages the server's lifetime (start, shutdown).
  • redis_url (session scope) Starts redislite server and provides the server's socket address.
  • redis_factory (session scope) a context manager to start/shutdown redislite server.

Auto flush data between tests

By default the plugin erases all data in Redis between tests. If you would like to change the behaviour define the fixture:

    @pytest.fixture
    def redis_autoflash():
        return False

You may define it for a module or whole tests session.

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/pytest-redislite/issues

Contributing

Development of the project happens at: https://github.com/klen/pytest-redislite

License

Licensed under a MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-redislite-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

pytest_redislite-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-redislite-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-redislite-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pytest-redislite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 087e3c33a05adebd4ced5b8f53e95375d2c57e2b235d828156c084e7e5f21a09
MD5 b6d29b24a6c0fedf1f250aa6a17aa562
BLAKE2b-256 436bdd4becc352875dc5e11be26cab72a557ddd509b8b5e464849123a977d08c

See more details on using hashes here.

File details

Details for the file pytest_redislite-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_redislite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6c0af71f349fc7ee9cdf763bfde31165ef311ffad059e3959f64dc6e6f8cc9f
MD5 e6400702483aa95b6664eee6d3ac8c6e
BLAKE2b-256 3359800994426c9ad0ee49875a3bd69b01d4f5ca7d70d63d8fac79ca59cfd139

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page