Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better config helpers API #602

Merged
merged 9 commits into from
Jan 14, 2019
Merged

Conversation

iky
Copy link
Contributor

@iky iky commented Jan 12, 2019

I found that patch is a better fit for the context manager name as it suggests that the config changes are returned back at exit:

@pytest.yield_fixture
def memory_rabbit_config():
    with nameko.config.patch({"AMQP_URI": "memory://"}):
        yield

When migrating a few services to global config I learned that having also a decorator for setting up test function context config would be very handy:

@nameko.config.patch({"AMQP_URI": "memory://"})
def test_spam():
    assert nameko.config["AMQP_URI"] == "memory://"

I also placed these helpers straight on config object having them available straight away and making the config API clearer.

* Move `update_config` and `setup_config` helper methods from module and
  place them on config object itself.
* Rename both helper context managers to `patch` and use `clear` argument
  of `patch` to replace the whole config.
* Keep `setup` as simple method only (also straight on `config`)
@iky iky changed the title [WIP] Better config api Better config helpers API Jan 12, 2019
Copy link
Member

@mattbennett mattbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ So much nicer!

Just a couple of tiny comments

@pytest.yield_fixture
def memory_rabbit_config():
with nameko.config.patch({"AMQP_URI": "memory://"}):
yield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little confusing that this fixture is defined but not used. I think you can drop this and just demonstrate the decorator usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


"""

config = self.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to call this data. I was briefly confused and thought the implementation below was writing to the global config var.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@mattbennett mattbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@mattbennett mattbennett merged commit e7d3fb2 into nameko:v3.0.0-rc Jan 14, 2019
@iky iky deleted the better-config-api branch January 14, 2019 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants