diff --git a/fakeredis/_server.py b/fakeredis/_server.py index b8db4243..9bd41573 100644 --- a/fakeredis/_server.py +++ b/fakeredis/_server.py @@ -3,6 +3,7 @@ import queue import threading import time +import uuid import warnings import weakref from collections import defaultdict @@ -51,7 +52,7 @@ def __init__(self, *args, **kwargs): self.server_key = path else: host, port = kwargs.get('host'), kwargs.get('port') - self.server_key = 'shared' if host is None or port is None else f'{host}:{port}' + self.server_key = uuid.uuid4().hex if host is None or port is None else f'{host}:{port}' self.server_key += f'v{version}' self._server = FakeServer.get_server(self.server_key, version=version) self._server.connected = connected @@ -125,7 +126,11 @@ def __init__(self, *args, server=None, connected=True, version=7, **kwargs): parameters = inspect.signature(redis.Redis.__init__).parameters parameter_names = list(parameters.keys()) default_args = parameters.values() - kwds = {p.name: p.default for p in default_args if p.default != inspect.Parameter.empty} + ignore_default_param_values = {'host', 'port', 'db'} + kwds = {p.name: p.default + for p in default_args + if (p.default != inspect.Parameter.empty + and p.name not in ignore_default_param_values)} kwds.update(kwargs) if not kwds.get('connection_pool', None): charset = kwds.get('charset', None) diff --git a/poetry.lock b/poetry.lock index b78ff596..434608f9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -483,14 +483,14 @@ pyflakes = ">=3.0.0,<3.1.0" [[package]] name = "hypothesis" -version = "6.72.4" +version = "6.74.0" description = "A library for property-based testing" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "hypothesis-6.72.4-py3-none-any.whl", hash = "sha256:9873eed54abc0611c5ed6c51df508e196f8204270f98c41264dcd052f6fbad07"}, - {file = "hypothesis-6.72.4.tar.gz", hash = "sha256:a8487696a0e0e4e1d5e5205a2496d155b0f54e440dfebc0c9224ea1599f17404"}, + {file = "hypothesis-6.74.0-py3-none-any.whl", hash = "sha256:6f19e61ac13bd35d5271b2788fd51b1e8cc673696b7a353d9a425960113efdbf"}, + {file = "hypothesis-6.74.0.tar.gz", hash = "sha256:b933baab6569c6639f6d8e1232ecc9f5388faa0cc5fba15cfc4d3447143b5965"}, ] [package.dependencies] @@ -892,14 +892,14 @@ testing = ["pytest", "pytest-cov"] [[package]] name = "platformdirs" -version = "3.3.0" +version = "3.4.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "platformdirs-3.3.0-py3-none-any.whl", hash = "sha256:ea61fd7b85554beecbbd3e9b37fb26689b227ffae38f73353cbcc1cf8bd01878"}, - {file = "platformdirs-3.3.0.tar.gz", hash = "sha256:64370d47dc3fca65b4879f89bdead8197e93e05d696d6d1816243ebae8595da5"}, + {file = "platformdirs-3.4.0-py3-none-any.whl", hash = "sha256:01437886022decaf285d8972f9526397bfae2ac55480ed372ed6d9eca048870a"}, + {file = "platformdirs-3.4.0.tar.gz", hash = "sha256:a5e1536e5ea4b1c238a1364da17ff2993d5bd28e15600c2c8224008aff6bbcad"}, ] [package.dependencies] @@ -1171,14 +1171,14 @@ ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)" [[package]] name = "requests" -version = "2.28.2" +version = "2.29.0" description = "Python HTTP for Humans." category = "dev" optional = false -python-versions = ">=3.7, <4" +python-versions = ">=3.7" files = [ - {file = "requests-2.28.2-py3-none-any.whl", hash = "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa"}, - {file = "requests-2.28.2.tar.gz", hash = "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf"}, + {file = "requests-2.29.0-py3-none-any.whl", hash = "sha256:e8f3c9be120d3333921d213eef078af392fba3933ab7ed2d1cba3b56f2568c3b"}, + {file = "requests-2.29.0.tar.gz", hash = "sha256:f2e34a75f4749019bb0e3effb66683630e4ffeaf75819fb51bebef1bf5aef059"}, ] [package.dependencies] @@ -1223,14 +1223,14 @@ idna2008 = ["idna"] [[package]] name = "rich" -version = "13.3.4" +version = "13.3.5" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" category = "dev" optional = false python-versions = ">=3.7.0" files = [ - {file = "rich-13.3.4-py3-none-any.whl", hash = "sha256:22b74cae0278fd5086ff44144d3813be1cedc9115bdfabbfefd86400cb88b20a"}, - {file = "rich-13.3.4.tar.gz", hash = "sha256:b5d573e13605423ec80bdd0cd5f8541f7844a0e71a13f74cf454ccb2f490708b"}, + {file = "rich-13.3.5-py3-none-any.whl", hash = "sha256:69cdf53799e63f38b95b9bf9c875f8c90e78dd62b2f00c13a911c7a3b9fa4704"}, + {file = "rich-13.3.5.tar.gz", hash = "sha256:2d11b9b8dd03868f09b4fffadc84a6a8cda574e40dc90821bd845720ebb8e89c"}, ] [package.dependencies] @@ -1295,14 +1295,14 @@ files = [ [[package]] name = "tox" -version = "4.5.0" +version = "4.5.1" description = "tox is a generic virtualenv management and test command line tool" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "tox-4.5.0-py3-none-any.whl", hash = "sha256:dae5823ac7b31514d33c6aabc332f19187d7842d1e07d88f00dd329e79a1737d"}, - {file = "tox-4.5.0.tar.gz", hash = "sha256:231382d5ecda16878c572a252158219a5d43936fd49da92a0d811ec0debfef87"}, + {file = "tox-4.5.1-py3-none-any.whl", hash = "sha256:d25a2e6cb261adc489604fafd76cd689efeadfa79709965e965668d6d3f63046"}, + {file = "tox-4.5.1.tar.gz", hash = "sha256:5a2eac5fb816779dfdf5cb00fecbc27eb0524e4626626bb1de84747b24cacc56"}, ] [package.dependencies] diff --git a/pyproject.toml b/pyproject.toml index 6c4ebb8b..54d89148 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ name = "fakeredis" packages = [ { include = "fakeredis" }, ] -version = "2.11.1" +version = "2.11.2" description = "Fake implementation of redis API for testing purposes." readme = "README.md" keywords = ["redis", "RedisJson", ] diff --git a/test/test_general.py b/test/test_general.py index 0f798218..bf99c4b4 100644 --- a/test/test_general.py +++ b/test/test_general.py @@ -23,3 +23,14 @@ def test_asyncioio_is_used(): def test_unknown_command(r): with pytest.raises(redis.ResponseError): raw_command(r, '0 3 3') + + +def test_new_server_when_no_params(): + from fakeredis import FakeRedis + + fake_redis_1 = FakeRedis() + fake_redis_2 = FakeRedis() + + fake_redis_1.set("foo", "bar") + + assert fake_redis_2.get("foo") is None diff --git a/test/test_init_args.py b/test/test_init_args.py index 1e934714..0ba18c74 100644 --- a/test/test_init_args.py +++ b/test/test_init_args.py @@ -26,10 +26,10 @@ def test_multidb(r, create_redis): class TestInitArgs: def test_singleton(self): shared_server = fakeredis.FakeServer() - r1 = fakeredis.FakeStrictRedis() - r2 = fakeredis.FakeStrictRedis(server=fakeredis.FakeServer()) - r3 = fakeredis.FakeStrictRedis(server=shared_server) - r4 = fakeredis.FakeStrictRedis(server=shared_server) + r1 = fakeredis.FakeRedis() + r2 = fakeredis.FakeRedis(server=fakeredis.FakeServer()) + r3 = fakeredis.FakeRedis(server=shared_server) + r4 = fakeredis.FakeRedis(server=shared_server) r1.set('foo', 'bar') r3.set('bar', 'baz') @@ -66,13 +66,9 @@ def test_from_url_user_password(self): assert db.get('foo') == b'bar' def test_from_url_with_db_arg(self): - db = fakeredis.FakeStrictRedis.from_url( - 'redis://localhost:6379/0') - db1 = fakeredis.FakeStrictRedis.from_url( - 'redis://localhost:6379/1') - db2 = fakeredis.FakeStrictRedis.from_url( - 'redis://localhost:6379/', - db=2) + db = fakeredis.FakeStrictRedis.from_url('redis://localhost:6379/0') + db1 = fakeredis.FakeStrictRedis.from_url('redis://localhost:6379/1') + db2 = fakeredis.FakeStrictRedis.from_url('redis://localhost:6379/', db=2) db.set('foo', 'foo0') db1.set('foo', 'foo1') db2.set('foo', 'foo2') @@ -82,14 +78,11 @@ def test_from_url_with_db_arg(self): def test_from_url_db_value_error(self): # In case of ValueError, should default to 0, or be absent in redis-py 4.0 - db = fakeredis.FakeStrictRedis.from_url( - 'redis://localhost:6379/a') + db = fakeredis.FakeStrictRedis.from_url('redis://localhost:6379/a') assert db.connection_pool.connection_kwargs.get('db', 0) == 0 def test_can_pass_through_extra_args(self): - db = fakeredis.FakeStrictRedis.from_url( - 'redis://localhost:6379/0', - decode_responses=True) + db = fakeredis.FakeStrictRedis.from_url('redis://localhost:6379/0', decode_responses=True) db.set('foo', 'bar') assert db.get('foo') == 'bar'