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

Updating tests to use real and fake broker_settings.yaml #216

Closed

Conversation

Griffin-Sullivan
Copy link
Collaborator

Fixes #212. All of the tests that are non-functional will make backup files for your settings and inventory and copy in test settings. Once the test is finished they are reset to normal.

image

@Griffin-Sullivan Griffin-Sullivan marked this pull request as draft May 26, 2023 15:38
@Griffin-Sullivan Griffin-Sullivan force-pushed the test-update branch 3 times, most recently from bff4974 to ce6c35b Compare June 9, 2023 15:52
@Griffin-Sullivan Griffin-Sullivan marked this pull request as ready for review June 9, 2023 15:52
tests/functional/test_containers.py Outdated Show resolved Hide resolved
Comment on lines +113 to +115
settings.clean()
settings.update(_settings.as_dict())
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to have settings and _settings alongside when one is already living in the module context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I understand the question. The reason for having the two here is that settings lives in the module context and we use this function to update that settings object with what we get from _settings. I'm pretty sure we were not able to just reset settings to another Dynaconf object because then it would lose context in places that it was already imported in, but I honestly can't remember at this point.

_sensitive_attrs = []

def __init__(self, **kwargs):
self._construct_params = []
cls_name = self.__class__.__name__
logger.debug(f"{cls_name} provider instantiated with {kwargs=}")
self.instance = kwargs.pop(f"{cls_name}", None)
if not self._settings_id == settings._id:
logger.debug("Settings object has been reloaded, reloading provider settings")
Copy link
Member

Choose a reason for hiding this comment

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

What is the case when we need to reload the settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For running the test suite we need to change the settings file being used. Now that we automatically look for settings in ~/.broker we need to change it to our broker_settings for testing when the tests are running.

)
settings.clean()
settings.update(_settings.as_dict())
settings._id = str(uuid.uuid4())
Copy link
Member

Choose a reason for hiding this comment

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

Could that be renamed to something like _broker_settings_id to be sure that _id does not collide with anything private of Dynaconf?

@@ -15,3 +17,21 @@ def set_envars(request):
os.environ[request.param[0]] = request.param[1]
yield
del os.environ[request.param[0]]

@pytest.fixture(scope="module")
def temp_settings_and_inventory():
Copy link
Member

Choose a reason for hiding this comment

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

What about using the tmp_path fixture and creating the new files in it? Then setting BROKER_DIRECTORY to tmp_path and unsettling it once the test is done?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could try it if you think that's an improvement over this implementation. @JacobCallahan any thoughts since you helped me with our current solution?

@Griffin-Sullivan Griffin-Sullivan marked this pull request as draft June 21, 2023 12:05
@JacobCallahan
Copy link
Member

@Griffin-Sullivan will you have a chance to revisit this sometime soon?

@Griffin-Sullivan
Copy link
Collaborator Author

Yeah I'll try to do it later today. I just need to get those 2 tests fixed and add @ogajduse's suggestions.

@JacobCallahan JacobCallahan changed the base branch from master to 0.4.0 July 6, 2023 20:45
@Griffin-Sullivan
Copy link
Collaborator Author

Screw this

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.

Test suite needs to be updated to look for broker_settings.yaml in ~/.broker
3 participants