nameko.testing.pytest

Functions

parse_config_option(text)

pytest_addoption(parser)

pytest_configure(config)

pytest_sessionstart(session)

empty_config()

mock_container(request, empty_config)

rabbit_manager(request)

vhost_pipeline(request, rabbit_manager)

rabbit_config(request, vhost_pipeline, rabbit_manager)

rabbit_ssl_config(request, rabbit_config)

amqp_uri(rabbit_config)

fast_teardown(request)

This fixture fixes the order of the container_factory, runner_factory

get_message_from_queue(amqp_uri)

container_factory()

runner_factory()

predictable_call_ids(request)

web_config(empty_config)

web_config_port(web_config)

web_session(web_config_port)

websocket(web_config_port)

Module Contents

nameko.testing.pytest.parse_config_option(text)[源代码]
nameko.testing.pytest.pytest_addoption(parser)[源代码]
nameko.testing.pytest.pytest_configure(config)[源代码]
nameko.testing.pytest.pytest_sessionstart(session)[源代码]
nameko.testing.pytest.empty_config()[源代码]
nameko.testing.pytest.mock_container(request, empty_config)[源代码]
nameko.testing.pytest.rabbit_manager(request)[源代码]
nameko.testing.pytest.vhost_pipeline(request, rabbit_manager)[源代码]
nameko.testing.pytest.rabbit_config(request, vhost_pipeline, rabbit_manager)[源代码]
nameko.testing.pytest.rabbit_ssl_config(request, rabbit_config)[源代码]
nameko.testing.pytest.amqp_uri(rabbit_config)[源代码]
nameko.testing.pytest.fast_teardown(request)[源代码]

This fixture fixes the order of the container_factory, runner_factory and rabbit_config fixtures to get the fastest possible teardown of tests that use them.

Without this fixture, the teardown order depends on the fixture resolution defined by the test, for example:

def test_foo(container_factory, rabbit_config):

pass # rabbit_config tears down first

def test_bar(rabbit_config, container_factory):

pass # container_factory tears down first

This fixture ensures the teardown order is:

  1. fast_teardown (this fixture)

  2. rabbit_config

  3. container_factory / runner_factory

That is, rabbit_config teardown, which removes the vhost created for the test, happens before the consumers are stopped.

Deleting the vhost causes the broker to sends a "basic-cancel" message to any connected consumers, which will include the consumers in all containers created by the container_factory and runner_factory fixtures.

This speeds up test teardown because the "basic-cancel" breaks the consumers' drain_events loop (http://bit.do/kombu-drain-events) which would otherwise wait for up to a second for the socket read to time out before gracefully shutting down.

For even faster teardown, we monkeypatch the consumers to ensure they don't try to reconnect between the "basic-cancel" and being explicitly stopped when their container is killed.

In older versions of RabbitMQ, the monkeypatch also protects against a race-condition that can lead to hanging tests.

Modern RabbitMQ raises a NotAllowed exception if you try to connect to a vhost that doesn't exist, but older versions (including 3.4.3, used by Travis) just raise a socket.error. This is classed as a recoverable error, and consumers attempt to reconnect. Kombu's reconnection code blocks until a connection is established, so consumers that attempt to reconnect before being killed get stuck there.

nameko.testing.pytest.get_message_from_queue(amqp_uri)[源代码]
nameko.testing.pytest.container_factory()[源代码]
nameko.testing.pytest.runner_factory()[源代码]
nameko.testing.pytest.predictable_call_ids(request)[源代码]
nameko.testing.pytest.web_config(empty_config)[源代码]
nameko.testing.pytest.web_config_port(web_config)[源代码]
nameko.testing.pytest.web_session(web_config_port)[源代码]
nameko.testing.pytest.websocket(web_config_port)[源代码]