Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
leapp internally performs os.chdir now, which is problematic in
tests. Add mocks for os.chdir where needed to not crash during
tests.
  • Loading branch information
Michal Hecko committed Oct 29, 2024
1 parent 4b81e73 commit 41618ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tests/scripts/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
_DIALOG_SCOPE = 'test-dialog'

_WORKFLOW_METADATA_FIELDS = ('description', 'name', 'phases', 'short_name', 'tag')
_ACTOR_METADATA_FIELDS = ('class_name', 'name', 'description', 'phase', 'tags', 'consumes', 'produces', 'path')
_ACTOR_METADATA_FIELDS = ('class_name', 'config', 'config_schemas', 'name', 'description',
'phase', 'tags', 'consumes', 'produces', 'path')

_TEST_WORKFLOW_METADATA = {
'description': 'No description has been provided for the UnitTest workflow.',
Expand Down Expand Up @@ -144,15 +145,15 @@ def test_store_actor_metadata(monkeypatch, repository_dir):
# ---
with repository_dir.as_cwd():
logger = logging.getLogger('leapp.actor.test')
with mock.patch.object(logger, 'log') as log_mock:
with mock.patch.object(logger, 'log') as log_mock, mock.patch('os.chdir'):
definition = ActorDefinition('actors/test', '.', log=log_mock)
with mock.patch('leapp.repository.actor_definition.get_actor_metadata', return_value=_TEST_ACTOR_METADATA):
with mock.patch('leapp.repository.actor_definition.get_actors', return_value=[True]):
definition._module = True

monkeypatch.setenv('LEAPP_EXECUTION_ID', _CONTEXT_NAME)
monkeypatch.setenv('LEAPP_HOSTNAME', _HOSTNAME)
store_actor_metadata(definition, 'test-phase')
store_actor_metadata(definition, 'test-phase', config={})
monkeypatch.delenv('LEAPP_EXECUTION_ID')
monkeypatch.delenv('LEAPP_HOSTNAME')

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_repository_actor_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def test_actor_definition(repository_dir):
with repository_dir.as_cwd():
with repository_dir.as_cwd(), mock.patch('os.chdir', return_value=None):
logger = logging.getLogger('leapp.actor.test')
with mock.patch.object(logger, 'log') as log_mock:
definition = ActorDefinition('actors/test', '.', log=log_mock)
Expand Down

0 comments on commit 41618ae

Please sign in to comment.