owned this note
owned this note
Published
Linked with GitHub
# Upgrading to Nameko 3.X
## What's New
* Configuration imrovements
* Configuration loaded from a file or declared in the CLI is now available in a global object
* Configuration may now be declared on the CLI
* Configuration access via the service container is now deprecated.
* Builtin extensions and other facilities that read the configuration now access it via the global
* CLI improvements
* CLI refactored to be more robust, reliable and extendable
* Command `backport` removed, `run` informs about how to connect to the backport port.
* Parameter `prefetch_count` exposed as a first-class citizen, rather than inheriting `max_workers`.
* A new `ClusterRpc` DependencyProvider was added, allowing services to make RPC calls without prior knowledge of the target service name. Additonally the word "proxy" was removed from RPC clients (the old names have been preserved for backwards compatibility):
* standalone `ServiceRpcProxy` renamed to `ServiceRpcClient`
* standalone `ClusterRpcProxy` renamed to `ClusterRpcClient`
* DependencyProvider `ServiceRpcProxy` renamed to `ServiceRpc`
* (DependencyProvider`ClusterRpc` added)
### Configuration available at any point
The new `nameko.config` dictionary allows you to access service configuration at any point including service class definition:
```python
from nameko.messaging import Consumer
from nameko import config
class Service:
@consume(
queue=Queue(
exchange=config["MY_EXCHANGE"],
routing_key=config["MY_ROUTING_KEY"],
name=config["MY_QUEUE_NAME"]
),
prefetch_count=config["MY_CONSUMER_PREFETCH_COUNT"]
)
def consume(self, payload):
pass
```
As you can see having config available outside service container also helps with configuring entrypoints and dependency providers by passing options to their constructors:
```python
from nameko import config
from nameko_sqlalchemy import Database
class Service:
db = Database(engine_options=config["DB_ENGINE_OPTIONS"])
```
Nameko 3.0 also comes with the possibility to define config entries from console when running a service or shell:
```bash
$ nameko run service \
--define AMQP_URI=pyamqp://someuser:*****@somehost/ \
--define max_workers=1000 \
--define SLACK="{'TOKEN': '*****'}"
```
### Configuration in tests
#### Config patching
Config has a `patch` helper object which can be used as a context manager or as a decorator. Follows an example of using config patching pattern in pytest fixture:
```python
import nameko
import pytest
@pytest.yield_fixture
def memory_rabbit_config():
with nameko.config.patch({"AMQP_URI": "memory://"}):
yield
```
> [name=iky] Add another config patching example - inside a test
Decorator apporach is handy when migrating services to global config:
```python
import nameko
@nameko.config.patch({"AMQP_URI": "memory://"})
def test_spam():
assert nameko.config["AMQP_URI"] == "memory://"
```
> [name=iky] add a real example
#### Changes to Config and Factory Fixtures
Both `container_factory` and `runner_factory` fixtures use to take config as required argument for setting up service container. In Nameko 3 the `config` argument is made optional which if passed would use `nameko.coinfig.patch` to wrap running container - patching config on container start and returning it back to it's original shape when exiting the test:
```python
def test_event_interface(container_factory):
container = container_factory(Service, config={"AMQP_URI": "..."})
container.start() # <- starts config patching scope, ending it when container
# stops (exit of the container_factory fixture)
# ...
def test_service_x_y_integration(runner_factory):
runner = runner_factory(config={"AMQP_URI": "..."}, ServiceX, ServiceY)
runner.start() # <- starts config patching scope, ending it when runner
# stops (exit of the runner_factory fixture)
# ...
```
This backward compatibility comes in handy when writing tests for Nameko community **extensions** compatible with both major versions.
However when writing new or upgrading existing **services** to run on Nameko 3.X it is recommended to use in tests the new *config patch pattern* instead:
```python
import nameko
@nameko.config.patch({"AMQP_URI": "memory://"})
def test_spam():
container = container_factory(Service)
container.start()
@nameko.config.patch({"AMQP_URI": "memory://"})
def test_service_x_y_integration(runner_factory):
runner = runner_factory(ServiceX, ServiceY)
runner.start()
@pytest.mark.usefixtures('rabbit_config')
def test_spam():
container = container_factory(Service)
container.start()
@pytest.mark.usefixtures('rabbit_config')
def test_service_x_y_integration(runner_factory):
runner = runner_factory(ServiceX, ServiceY)
runner.start()
```
> Users can define test config for their services reusing existing nameko config fixtures::
```python
import nameko
import pytest
@pytest.fixture(autouse=True)
def config(web_config, rabbit_config):
config = {
# some custom testing config, defined in place or loaded from file ...
}
config.update(web_config)
config.update(rabbit_config)
with nameko.config.patch(config):
yield
```
> There is a partial change to the use of `empty_config`, `rabbit_config` and `web_config` which now do NOT return the config dictionary any more, instead they use `nameko.config_update` to update `nameko.config` just for the context of the tests these fixture are used for - this is also a **braking change**.
### Backward compatible Config on Container
`Container.config` is now deprecated in favor of `nameko.config` and no built-in Nameko component uses it any more. However it still returns, so existing community extensions will still work.
Nameko 3 direct use of config:
```python
from nameko import config
from nameko.extensions import DependencyProvider
class Database(DependencyProvider):
def setup(self):
db_uris = config[DB_URIS_KEY] # <- Nameko 3 way, won't work with Nameko 2!
# ...
```
Having the dependency provider (or any Nameko extension) written that way will work well with Nameko 3 but it won't work with Nameko 2! Therefore in Nameko 3 the container config still exists and this backward compatibility allows for extensions to be used in both Nameko 2 and Nameko 3:
```python
from nameko.extensions import DependencyProvider
class Database(DependencyProvider):
def setup(self):
db_uris = self.container.config[DB_URIS_KEY] # <- still works, Nameko 2 & 3
# ...
```
Note that in Nameko 3 a **deprecation warning is raised if the container config is accessed**:
```
.../nameko/containers.py:173: DeprecationWarning: Use ``nameko.config`` instead.
warnings.warn("Use ``nameko.config`` instead.", DeprecationWarning)
```
### Runners
In Nameko 3 `ServiceContainer` and `ServiceRunner` **do NOT take config dictionary anymore**!
```python
import nameko
from nameko.containers import ServiceContainer
nameko.config["AMQP_URI"] = "pyamqp://someuser:*****@somehost/"
container = ServiceContainer(Service)
container.start()
# AMQP extensions will connect as someuser to RabbitMQ broker at somehost ...
container.stop()
```
Same for the runner:
```python
from nameko.runners import ServiceRunner
nameko.config["AMQP_URI"] = "pyamqp://someuser:*****@somehost/"
runner = ServiceRunner()
runner.add_service(ServiceA)
runner.add_service(ServiceB)
runner.start()
# AMQP extensions will connect as someuser to RabbitMQ broker at somehost ...
runner.stop()
```
### Standalone
> Same approach as with the other runners, but reusing the existing context manager in case of standalone RPC proxy. By making the `config` optional argument of `ClusterRpcProxy`, one can still do
>
> ```
> from nameko.standalone.rpc import ClusterRpcProxy
>
> config = {
> 'AMQP_URI': AMQP_URI # e.g. "pyamqp://guest:guest@localhost"
> }
>
> with ClusterRpcProxy(config) as cluster_rpc:
> cluster_rpc.service_x.remote_method("hellø") # "hellø-x-y"
> ```
>
> If a config is passed, the proxy context is also wrapped in `config_setup`, otherwise nameko global config is used as it is.
>
> In case of the (so far undocumented) standalone event publisher, the dispatcher can be also made context manager with optional config:
>
> ```
> from nameko.standalone.events import event_dispatcher
>
> config = {
> 'AMQP_URI': AMQP_URI # e.g. "pyamqp://guest:guest@localhost"
> }
>
> with event_dispatcher(config) as dispatcher:
> dispatcher.dispatch('some_service', 'some_event', {'some': 'payload'})
> ```
>
> or by using `config_setup` as context manager (probably only if two clusters are involved, or some other complex case):
>
> ```
> from nameko import config_setup
> from nameko.standalone.events import event_dispatcher
>
> with config_setup(config_cluster_foo):
> dispatcher = event_dispatcher()
> dispatcher.dispatch('some_service', 'some_event', {'some': 'payload'})
>
> with config_setup(config_cluster_bar):
> dispatcher = event_dispatcher()
> dispatcher.dispatch('some_other_service', 'some_event', {'some': 'payload'})
> ```
>
> or simply as as a function (in a script or when bootstrapping something more complex than a simple script):
>
> ```
> from nameko import config_setup
> from nameko.standalone.events import event_dispatcher
>
> config = {
> 'AMQP_URI': AMQP_URI # e.g. "pyamqp://guest:guest@localhost"
> }
>
> config_setup(config):
> dispatcher = event_dispatcher()
> dispatcher.dispatch('some_service', 'some_event', {'some': 'payload'})
> ```
>
> Maybe all three should work. The last two should definitely work.
### Other Configuration Related Changes
* `--broker` CLI option is deprecated in favor of `--define` and `--config`. It still works (for now) but raises a deprecation warning [is this still true? looks like the warning slipped through in the cli refactor].
* Built-in `Config` dependency provider is now deprecated as the config can be accessed and read directly.
## Upgrading Services
### Breaking changes
### Using config inside entrypoints
The `nameko.dependencies.config.` was deprecated but it's still available.
### Tests
```diff
diff --git a/src/properties/services/core/service.py b/src/properties/services/core/service.py
index 1ac0954..edfced2 100644
--- a/src/properties/services/core/service.py
+++ b/src/properties/services/core/service.py
@@ -10,6 +10,7 @@ from functools import partial
+from nameko import config
from nameko.events import EventDispatcher, event_handler
from nameko.messaging import Publisher
from nameko.rpc import RpcProxy, rpc
@@ -1384,7 +1385,7 @@ class PropertiesCore(
def health_check(self):
- version_file = os.path.join(self.config['VERSION_FILE'])
+ version_file = os.path.join(config['VERSION_FILE'])
result = {'ok': True}
diff --git a/test/conftest.py b/test/conftest.py
index 891759d..bd79ae0 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -1,6 +1,7 @@
import os
import charlatan
+import nameko
import pytest
import requests_mock as requests_mock_lib
import yaml
@@ -46,7 +47,7 @@ def data_fixture_manager(project_root):
@pytest.yield_fixture
def redis_client(config):
client = redis.StrictRedis.from_url(
- config.get('REDIS_URI'))
+ nameko.config.get('REDIS_URI'))
yield client
client.flushdb()
@@ -95,14 +96,8 @@ def test_config(service_root):
with open(config_file) as stream:
config = yaml.load(stream.read())
config['UPDATE_SERIAL_ENABLED'] = False
- return config
-
-
-@pytest.fixture()
-def web_config(web_config, test_config):
- config = test_config.copy()
- config.update(web_config)
- return config
+ with nameko.config.patch(config, clear=True):
+ yield
@pytest.fixture(scope='session')
@@ -112,7 +107,7 @@ def model_base():
@pytest.fixture(scope="module")
def db_uri(test_config):
- return test_config['DB_URIS']['properties:Base']
+ return nameko.config['DB_URIS']['properties:Base']
@pytest.yield_fixture(scope="module")
@@ -142,14 +137,6 @@ def db_session(db_connection):
db_session.close()
-@pytest.fixture
-def config(web_config, test_config, rabbit_config):
- config = test_config.copy()
- config.update(web_config)
- config.update(rabbit_config)
- return config
-
-
# ---
@pytest.fixture
diff --git a/test/integration/bdd/environment.py b/test/integration/bdd/environment.py
index 0509bb1..8437aa8 100644
--- a/test/integration/bdd/environment.py
+++ b/test/integration/bdd/environment.py
@@ -1,3 +1,4 @@
+import nameko
from nameko.cli.main import setup_yaml_parser
from nameko.standalone.rpc import ClusterRpcProxy
@@ -7,9 +8,13 @@ setup_yaml_parser()
def before_feature(context, feature):
+
if 'AMQP_URI' not in context.config.userdata:
context.config.userdata['AMQP_URI'] = (
'amqp://guest:guest@localhost:5672/')
+
+ nameko.config.setup(context.config.userdata)
+
context.cluster_rpc_proxy = ClusterRpcProxy(context.config.userdata)
context.rpc = context.cluster_rpc_proxy.start()
diff --git a/test/interface/core/base/test_health_check.py b/test/interface/core/base/test_health_check.py
index f5c3910..3e949bc 100644
--- a/test/interface/core/base/test_health_check.py
+++ b/test/interface/core/base/test_health_check.py
@@ -4,9 +4,9 @@ from nameko.standalone.rpc import ServiceRpcProxy
class TestHealthCheck:
- @pytest.mark.usefixtures('db_session', 'properties_service')
- def test_rpc_call(self, config):
- with ServiceRpcProxy('properties', config) as proxy:
+ @pytest.mark.usefixtures('config', 'db_session', 'properties_service')
+ def test_rpc_call(self):
+ with ServiceRpcProxy('properties') as proxy:
result = proxy.rpc_health_check()
expected_result = {
diff --git a/test/interface/core/conftest.py b/test/interface/core/conftest.py
index 728fb47..58e9c59 100644
--- a/test/interface/core/conftest.py
+++ b/test/interface/core/conftest.py
@@ -23,7 +23,7 @@ def create_service_meta(container_factory, config):
ServiceMeta = namedtuple(
'ServiceMeta', ['container'] + list(dependency_map.keys()))
- container = container_factory(service_cls, config)
+ container = container_factory(service_cls)
replace_dependencies(container, **dependency_map)
container.start()
@@ -92,5 +92,5 @@ def validate_paging_response(
@pytest.yield_fixture
def properties_rpc(config):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
yield proxy
diff --git a/test/interface/core/excel_listings/test_generator.py b/test/interface/core/excel_listings/test_generator.py
index b4d8015..b639e25 100644
--- a/test/interface/core/excel_listings/test_generator.py
+++ b/test/interface/core/excel_listings/test_generator.py
@@ -187,11 +187,11 @@ class TestGenerateExcelListingsHttp:
]
+@pytest.mark.usefixtures("config")
class TestGenerateExcelListingsRpc:
def test_can_get_workbook(
- self, config, unit_type, property_, available_listings,
- properties_service
+ self, unit_type, property_, available_listings, properties_service
):
properties_service.landlords_rpc.get_landlord.return_value = {
@@ -199,7 +199,7 @@ class TestGenerateExcelListingsRpc:
'name': 'landlord'
}
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
result = proxy.generate_excel_listings(property_.id)
assert result['filename'] == '{}_listings.xlsx'.format(property_.id)
@@ -207,9 +207,9 @@ class TestGenerateExcelListingsRpc:
assert_workbook_ok(wb, property_, unit_type)
def test_unknown_property(
- self, config, unit_type, property_, available_listings,
+ self, unit_type, property_, available_listings,
):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
with pytest.raises(RemoteError) as exc:
proxy.generate_excel_listings(999)
assert 'EntityNotFound' in str(exc)
diff --git a/test/interface/core/excel_listings/test_ingestor.py b/test/interface/core/excel_listings/test_ingestor.py
index d2ac869..4ed4a7a 100644
--- a/test/interface/core/excel_listings/test_ingestor.py
+++ b/test/interface/core/excel_listings/test_ingestor.py
@@ -400,13 +400,13 @@ class TestIngestExcelListingsHttp:
class TestIngestExcelListingsRPC:
+ @pytest.mark.usefixtures("config")
def test_can_read_listings_via_rpc(
- self, workbook_file, properties_service, config, expected_listings,
- property_
+ self, workbook_file, properties_service, expected_listings, property_
):
base64_workbook = b64encode(workbook_file.read()).decode()
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
# Post the file back to "ingest" it. (via RPC)
proxy.ingest_excel_listings(property_.id, base64_workbook)
diff --git a/test/interface/core/properties/test_get.py b/test/interface/core/properties/test_get.py
index fafecd4..c0d4633 100644
--- a/test/interface/core/properties/test_get.py
+++ b/test/interface/core/properties/test_get.py
@@ -4,7 +4,6 @@ from test import assert_dict_equal, assert_items_equal
import pytest
from mock import call, patch
-from nameko.contextdata import LANGUAGE_CONTEXT_KEY
from nameko.exceptions import RemoteError
from nameko.standalone.rpc import ServiceRpcProxy
@@ -847,7 +846,6 @@ class TestGetPropertySummaryBySlug:
'name': "WBSA",
'slug': "wbsa",
}
- properties_rpc.worker_ctx.data[LANGUAGE_CONTEXT_KEY] = 'es-es'
results = properties_rpc.get_property_summary(property_.slug)
assert_items_equal(
expected_translated_property_summary.pop('facilities'),
@@ -869,7 +867,6 @@ class TestGetPropertySummaryBySlug:
'slug': "wbsa",
}
- properties_rpc.worker_ctx.data[LANGUAGE_CONTEXT_KEY] = 'es-es'
results = properties_rpc.get_property_summary(id_=property_.id)
assert_items_equal(
@@ -883,7 +880,6 @@ class TestGetPropertySummaryBySlug:
self, properties_rpc, property_, service,
expected_not_translated_property_summary
):
- properties_rpc.worker_ctx.data[LANGUAGE_CONTEXT_KEY] = 'es-es'
results = properties_rpc.get_property_summary(property_.slug)
assert_items_equal(
diff --git a/test/interface/core/properties/test_list.py b/test/interface/core/properties/test_list.py
index 8aa90ab..5d01a22 100644
--- a/test/interface/core/properties/test_list.py
+++ b/test/interface/core/properties/test_list.py
@@ -13,7 +13,7 @@ from test.interface.core.conftest import (
@pytest.fixture(params=['http', 'rpc'])
-@pytest.mark.usefixtures('properties_service')
+@pytest.mark.usefixtures('config', 'properties_service')
def list_properties(request, config, web_session):
"""
Return list_properties endpoint caller for both transports (HTTP and RPC)
@@ -55,7 +55,7 @@ def list_properties(request, config, web_session):
context_data = {LANGUAGE_CONTEXT_KEY: language}
else:
context_data = {}
- with ServiceRpcProxy('properties', config, context_data) as proxy:
+ with ServiceRpcProxy('properties', context_data) as proxy:
response = proxy.list_properties(**kwargs)
return response
@@ -152,8 +152,9 @@ def test_can_filter_properties(
assert len(results["properties"]) == 2
+@pytest.mark.usefixtures("config")
def test_list_properties_with_archived_properties(
- config, db_session, no_listings
+ db_session, no_listings
):
properties = []
property_names = ('active_02', 'archived_01', 'active_01')
@@ -177,7 +178,7 @@ def test_list_properties_with_archived_properties(
db_session.add_all(properties)
db_session.commit()
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_properties(
order_by=[dict(field='name', direction='asc')]
)
@@ -185,7 +186,7 @@ def test_list_properties_with_archived_properties(
returned_prop_names = [p['name'] for p in response["properties"]]
assert ['active_01', 'active_02'] == returned_prop_names
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_properties(
order_by=[dict(field='name', direction='asc')],
allow_archived=True,
diff --git a/test/interface/core/test_unit_types.py b/test/interface/core/test_unit_types.py
index 58580f9..d6c1336 100644
--- a/test/interface/core/test_unit_types.py
+++ b/test/interface/core/test_unit_types.py
@@ -85,7 +85,7 @@ def test_can_get_unit_type_http_no_bathroom_type(
def test_can_get_unit_type_no_bathroom_type(
unit_type, property_, property_distinctions, unit_type_data, config
):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
response = proxy.get_unit_type(unit_type.id)
dummy_distinction = get_dummy_distinctions()[1000004]
@@ -103,7 +103,7 @@ def test_can_get_unit_type_private_bathroom_type(
unit_type_with_private_bathroom, property_, property_distinctions, unit_type_data,
config
):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
response = proxy.get_unit_type(unit_type_with_private_bathroom.id)
dummy_distinction = get_dummy_distinctions()[1000002]
@@ -125,7 +125,7 @@ def test_cannot_get_unit_type_if_archived(
db_session.commit()
with pytest.raises(RemoteError) as exc:
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
proxy.get_unit_type(unit_type.id)
assert 'Unit Type not found' in str(exc)
@@ -139,7 +139,7 @@ def test_can_get_unit_type_if_archived_and_flag_is_set(
unit_type.archived = True
db_session.commit()
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
response = proxy.get_unit_type(unit_type.id, allow_archived=True)
# unit types without bathroom_type returns mixed bathroom
@@ -773,7 +773,7 @@ def list_unit_types_for_property(request, config, web_session):
context_data = {LANGUAGE_CONTEXT_KEY: language}
else:
context_data = {}
- with ServiceRpcProxy('properties', config, context_data) as proxy:
+ with ServiceRpcProxy('properties', context_data) as proxy:
response = proxy.list_unit_types_for_property(
property_id, **kwargs)
return response
@@ -785,7 +785,7 @@ def list_unit_types_for_property(request, config, web_session):
@pytest.mark.usefixtures('properties_service')
def test_list_unit_types(config, unit_type):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
results = proxy.list_unit_types()
unit_type_data = results['unit_types'][0]
@@ -799,7 +799,7 @@ def test_archived_unit_types_excluded_from_list_unit_types(
unit_type.archived = True
db_session.commit()
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
results = proxy.list_unit_types()
assert results['unit_types'] == []
@@ -812,7 +812,7 @@ def test_archived_unit_types_included_in_list_unit_types_if_flag_set(
unit_type.archived = True
db_session.commit()
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
results = proxy.list_unit_types(allow_archived=True)
unit_type_data = results['unit_types'][0]
@@ -822,7 +822,7 @@ def test_archived_unit_types_included_in_list_unit_types_if_flag_set(
@pytest.mark.usefixtures('properties_service')
def test_archive_unit_type(config, unit_type, db_session, properties_service):
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
proxy.archive_unit_type(unit_type.id)
db_session.rollback()
@@ -914,7 +914,7 @@ def test_can_get_unit_types_with_listings(
):
db_session.add_all(unit_types)
db_session.commit()
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_unit_types_for_property(
property_.id, with_listings=True
)
@@ -945,7 +945,7 @@ def test_can_get_unit_types_for_property_by_slug_with_listings(
):
db_session.add_all(unit_types)
db_session.commit()
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_unit_types_for_property_by_slug(
property_.slug, with_listings=True
)
@@ -976,7 +976,7 @@ def test_can_get_unit_types_for_property_by_slug_without_listings(
):
db_session.add_all(unit_types)
db_session.commit()
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_unit_types_for_property_by_slug(
property_.slug, with_listings=False
)
@@ -998,7 +998,7 @@ def test_can_get_unit_types_for_property_by_slug_with_tenancy_periods(
):
db_session.add_all(unit_types)
db_session.commit()
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_unit_types_for_property_by_slug(
property_.slug,
with_listings=True,
@@ -1039,7 +1039,7 @@ def test_availability_on_property(
properties_service.listings_rpc.list_active_listings.return_value = (
{'listings': listings}
)
- with ServiceRpcProxy('properties', config, {}) as proxy:
+ with ServiceRpcProxy('properties', {}) as proxy:
response = proxy.list_unit_types_for_property_by_slug(
property_.slug, with_listings=True
)
@@ -1106,7 +1106,7 @@ def test_will_raise_property_not_found_from_list_unit_types_for_property_rpc(
):
invalid_property_id = 999
with pytest.raises(RemoteError) as exc_info:
- with ServiceRpcProxy('properties', config) as proxy:
+ with ServiceRpcProxy('properties') as proxy:
proxy.list_unit_types_for_property(invalid_property_id)
assert exc_info.value.exc_type == 'EntityNotFound'
diff --git a/test/interface/test_remote_exceptions.py b/test/interface/test_remote_exceptions.py
index ea623d5..b4cb0df 100644
--- a/test/interface/test_remote_exceptions.py
+++ b/test/interface/test_remote_exceptions.py
@@ -40,9 +40,10 @@ class ExampleService(object):
getattr(self.rpcproxy, method)(*args)
-def test_unexpected_error_in_remote_worker(container_factory, rabbit_config):
+@pytest.mark.usefixtures("rabbit_config")
+def test_unexpected_error_in_remote_worker(container_factory):
- container = container_factory(ExampleService, rabbit_config)
+ container = container_factory(ExampleService)
container.start()
with entrypoint_hook(container, "proxy") as proxy:
@@ -52,9 +53,10 @@ def test_unexpected_error_in_remote_worker(container_factory, rabbit_config):
assert not container._died.ready()
-def test_expected_error_in_remote_worker(container_factory, rabbit_config):
+@pytest.mark.usefixtures("rabbit_config")
+def test_expected_error_in_remote_worker(container_factory):
- container = container_factory(ExampleService, rabbit_config)
+ container = container_factory(ExampleService)
container.start()
with entrypoint_hook(container, "proxy") as proxy:
diff --git a/test/services/core/test_properties.py b/test/services/core/test_properties.py
index fd7083c..149fe2b 100644
--- a/test/services/core/test_properties.py
+++ b/test/services/core/test_properties.py
@@ -12,7 +12,7 @@ class TestListProperties:
@pytest.fixture
def service(self, config, runner_factory):
- runner = runner_factory(config, PropertiesCore)
+ runner = runner_factory(PropertiesCore)
container = get_container(runner, PropertiesCore)
class Service:
diff --git a/test/unit/core/conftest.py b/test/unit/core/conftest.py
index a7178c5..6b72361 100644
--- a/test/unit/core/conftest.py
+++ b/test/unit/core/conftest.py
@@ -14,4 +14,4 @@ def service_name():
@pytest.fixture
def service(config):
- return worker_factory(PropertiesCore, config=config)
+ return worker_factory(PropertiesCore)
diff --git a/test/unit/dependencies/test_storage.py b/test/unit/dependencies/test_storage.py
index ea5b607..0faa678 100644
--- a/test/unit/dependencies/test_storage.py
+++ b/test/unit/dependencies/test_storage.py
@@ -315,8 +315,7 @@ def list_properties(db_session):
@pytest.fixture
def container(test_config):
- return Mock(
- spec=ServiceContainer, config=test_config, service_name="properties")
+ return Mock(spec=ServiceContainer, service_name="properties")
@pytest.yield_fixture
```
## Upgrading Libraries
As the container config is still available in Nameko 3 (see Backward compatible Config on Container section), there is no change required in extensions source code and extensions made for Nameko 2 are automatically Nameko 3 ready and vice versa. In the future once dropping support for Nameko 2 reading config should be upgraded from using container config to direct access.
Also factory tests fixtures are made backward compatible still taking config dictionaries (see )
However what may be required to make an extension tests compatible with both Nameko major versions is to possibly change how the tests work with config. Nameko 3 config fixtures do not return config dictionary anymore (see Changes to Config and Factory Fixtures) which is a thing some tests may rely on.
Some tests ...:
no change to anything: