Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
.. image:: https://raw.githubusercontent.com/ClearcodeHQ/pytest-redis/master/logo.png :width: 100px :height: 100px
.. image:: https://img.shields.io/pypi/v/pytest-redis.svg :target: https://pypi.python.org/pypi/pytest-redis/ :alt: Latest PyPI version
.. image:: https://img.shields.io/pypi/wheel/pytest-redis.svg :target: https://pypi.python.org/pypi/pytest-redis/ :alt: Wheel Status
.. image:: https://img.shields.io/pypi/pyversions/pytest-redis.svg :target: https://pypi.python.org/pypi/pytest-redis/ :alt: Supported Python Versions
.. image:: https://img.shields.io/pypi/l/pytest-redis.svg :target: https://pypi.python.org/pypi/pytest-redis/ :alt: License
This is a pytest plugin, that enables you to test your code that relies on a running Redis database. It allows you to specify additional fixtures for Redis process and client.
Plugin contains three fixtures
Simply include one of these fixtures into your tests fixture list.
.. code-block:: python
#
def test_redis(redisdb):
"""Check that it's actually working on redis database."""
redisdb.set('test1', 'test')
redisdb.set('test2', 'test')
my_functionality = MyRedisBasedComponent()
my_functionality.do_something()
assert my_functionality.did_something
assert redisdb.get("did_it") == 1
For the example above works like following:
You can also create additional redis client and process fixtures if you'd need to:
.. code-block:: python
from pytest_redis import factories
redis_my_proc = factories.redis_proc(port=None)
redis_my = factories.redisdb('redis_my_proc')
def test_my_redis(redis_my):
"""Check that it's actually working on redis database."""
redis_my.set('test1', 'test')
redis_my.set('test2', 'test')
my_functionality = MyRedisBasedComponent()
my_functionality.do_something()
assert my_functionality.did_something
assert redis_my.get("did_it") == 1
.. note::
Each Redis process fixture can be configured in a different way than the others through the fixture factory arguments.
Some projects are using already running redis servers (ie on docker instances).
In order to connect to them, one would be using the redis_nooproc
fixture.
.. code-block:: python
redis_external = factories.redisdb('redis_nooproc')
def test_redis(redis_external):
"""Check that it's actually working on redis database."""
redis_external.set('test1', 'test')
redis_external.set('test2', 'test')
my_functionality = MyRedisBasedComponent()
my_functionality.do_something()
assert my_functionality.did_something
assert redis_external.get("did_it") == 1
Standard configuration options apply to it. Note that the modules
configuration option
has no effect with the redis_nooproc
fixture, it is the responsibility of the already
running redis server to be properly started with extension modules, if needed.
By default the redis_nooproc
fixture would connect to Redis
instance using 6379 port attempting to make a successful socket
connection within 15 seconds. The fixture will block your test run
within this timeout window. You can overwrite the timeout like so:
.. code-block:: python
# set the blocking wait to 5 seconds
redis_external = factories.redis_noproc(timeout=5)
def test_redis(redis_external):
"""Check that it's actually working on redis database."""
redis_external.set('test1', 'test')
# etc etc
These are the configuration options that are working on all levels with the redis_nooproc
fixture:
You can define your settings in three ways, it's fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:
* ``Fixture factory argument``
* ``Command line option``
* ``Configuration option in your pytest.ini file``
.. list-table:: Configuration options :header-rows: 1
Example usage:
.. code-block:: python
redis_proc = factories.redis_proc(port=8888)
--redis-port
command line option when you run your tests.. code-block:: bash
py.test tests --redis-port=8888
specify your port as redis_port
in your pytest.ini
file.
To do so, put a line like the following under the [pytest]
section of your pytest.ini
:
.. code-block:: ini
[pytest]
redis_port = 8888
Options below are for configuring redis client fixture.
+---------------------+--------------------------+---------------------+-------------------+---------+ | Redis client option | Fixture factory argument | Command line option | pytest.ini option | Default | +=====================+==========================+=====================+===================+=========+ | decode_response | decode | --redis-decode | redis_decode | False | +---------------------+--------------------------+---------------------+-------------------+---------+
Install pipenv and --dev dependencies first, Then run:
.. code-block:: bash
pipenv run tbump [NEW_VERSION]
FAQs
Redis fixtures and fixture factories for Pytest.
We found that pytest-redis demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.