Repository: reframe-hpc/reframe

Issue:
`--dry-run` wipes out the output test directory
Here's how to reproduce:

1. Run a test and check the output directory:

```console
$ ./bin/reframe -c unittests/resources/checks/hellocheck.py -n ^HelloTest -r
$ ls output/generic/default/builtin/HelloTest/
rfm_build.err  rfm_build.out  rfm_build.sh*  rfm_job.err    rfm_job.out    rfm_job.sh*
```

2. Re-run with `--dry-run`:

```console
$ ./bin/reframe -c unittests/resources/checks/hellocheck.py -n ^HelloTest -r
$ ls output/generic/default/builtin/HelloTest/
<empty>
```



Discussion:

Fix (patch):
diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py
index 72656022..9c623ae9 100644
--- a/reframe/core/pipeline.py
+++ b/reframe/core/pipeline.py
@@ -1737,10 +1737,11 @@ class RegressionTest(RegressionMixin, jsonext.JSONSerializable):
                 self.current_system.name, self._current_partition.name,
                 self._current_environ.name, self.short_name
             )
-            self._outputdir = runtime.make_outputdir(
-                self.current_system.name, self._current_partition.name,
-                self._current_environ.name, self.short_name
-            )
+            if not self.is_dry_run():
+                self._outputdir = runtime.make_outputdir(
+                    self.current_system.name, self._current_partition.name,
+                    self._current_environ.name, self.short_name
+                )
         except OSError as e:
             raise PipelineError('failed to set up paths') from e
 


Test changes:
diff --git a/unittests/test_cli.py b/unittests/test_cli.py
index a6cc007e..8810d80a 100644
--- a/unittests/test_cli.py
+++ b/unittests/test_cli.py
@@ -162,6 +162,19 @@ def test_check_success(run_reframe, tmp_path, run_action):
                           'reports' / 'run-report-0.json')
 
 
+def test_outputdir_dry_run(run_reframe, tmp_path):
+    # We need to make sure that outputdir is maintained if the same test is
+    # rerun with `--dry-run`
+
+    run_reframe(action='run', more_options=['-n', '^HelloTest'])
+    run_reframe(action='dry_run', more_options=['-n', '^HelloTest'])
+    prefix = (tmp_path / 'output' / 'generic' / 'default' /
+              'builtin' / 'HelloTest')
+    for path in ('rfm_build.err', 'rfm_build.out', 'rfm_build.sh',
+                 'rfm_job.err', 'rfm_job.out', 'rfm_job.sh'):
+        assert (prefix / path).exists()
+
+
 def test_check_restore_session_failed(run_reframe, tmp_path):
     run_reframe(
         checkpath=['unittests/resources/checks_unlisted/deps_complex.py']