diff --git a/src/aiida/cmdline/commands/cmd_archive.py b/src/aiida/cmdline/commands/cmd_archive.py index 4ed99bc883..2db9fbcd62 100644 --- a/src/aiida/cmdline/commands/cmd_archive.py +++ b/src/aiida/cmdline/commands/cmd_archive.py @@ -480,10 +480,12 @@ def _import_archive_and_migrate( from aiida.common.folders import SandboxFolder from aiida.tools.archive.abstract import get_format + from aiida.tools.archive.exceptions import ImportTestRun from aiida.tools.archive.imports import import_archive as _import_archive archive_format = get_format() filepath = ctx.obj['config'].get_option('storage.sandbox') or None + dry_run_success = f'import dry-run of archive {archive} completed. Profile storage unmodified.' with SandboxFolder(filepath=filepath) as temp_folder: archive_path = archive @@ -515,12 +517,19 @@ def _import_archive_and_migrate( echo.echo_report('proceeding with import of migrated archive') try: _import_archive(archive_path, archive_format=archive_format, **import_kwargs) + except ImportTestRun: + echo.echo_success(dry_run_success) + return except Exception as sub_exception: _echo_exception( f'an exception occurred while trying to import the migrated archive {archive}', sub_exception ) else: _echo_exception(f'an exception occurred while trying to import the archive {archive}', exception) + except ImportTestRun: + echo.echo_success(dry_run_success) + return + except Exception as exception: _echo_exception(f'an exception occurred while trying to import the archive {archive}', exception) diff --git a/tests/cmdline/commands/test_archive_import.py b/tests/cmdline/commands/test_archive_import.py index 92b6690433..b644859c50 100644 --- a/tests/cmdline/commands/test_archive_import.py +++ b/tests/cmdline/commands/test_archive_import.py @@ -49,6 +49,19 @@ def test_import_archive(run_cli_command, newest_archive): run_cli_command(cmd_archive.import_archive, options) +@pytest.mark.parametrize( + 'archive', + ( + get_archive_file('arithmetic.add.aiida', filepath='calcjob'), + get_archive_file('export_0.9_simple.aiida', filepath=ARCHIVE_PATH), + ), +) +def test_import_dry_run(run_cli_command, archive): + """Test import dry-run""" + result = run_cli_command(cmd_archive.import_archive, [archive, '--dry-run']) + assert f'import dry-run of archive {archive} completed' in result.output + + def test_import_to_group(run_cli_command, newest_archive): """Test import to existing Group and that Nodes are added correctly for multiple imports of the same, as well as separate, archives.