Repository: spack/spack

Issue:
The "test_checksum" unit test fails spuriously
### Steps to reproduce

Sometimes, when running CI on Github Actions, PRs report failures on the `test_checksum` unit test. The failures seem to be spurious, since re-running the same tests usually makes them pass.

### Error message

```
==================================== ERRORS ====================================
__ ERROR at teardown of test_checksum[arguments0-versions of preferred-test] ___

request = <SubRequest 'check_for_leftover_stage_files' for <Function test_checksum[arguments0-versions of preferred-test]>>
mock_stage = '/tmp/pytest-of-runner/pytest-0/mock-stage2'
ignore_stage_files = {'.lock', 'build_cache', 'spack-src', 'spack-stage-j44yj070'}

    @pytest.fixture(scope='function', autouse=True)
    def check_for_leftover_stage_files(request, mock_stage, ignore_stage_files):
        """
        Ensure that each (mock_stage) test leaves a clean stage when done.
    
        Tests that are expected to dirty the stage can disable the check by
        adding::
    
            @pytest.mark.disable_clean_stage_check
    
        and the associated stage files will be removed.
        """
        stage_path = mock_stage
    
        yield
    
        files_in_stage = set()
        try:
            stage_files = os.listdir(stage_path)
            files_in_stage = set(stage_files) - ignore_stage_files
        except OSError as err:
            if err.errno == errno.ENOENT:
                pass
            else:
                raise
    
        if 'disable_clean_stage_check' in request.keywords:
            # clean up after tests that are expected to be dirty
            for f in files_in_stage:
                path = os.path.join(stage_path, f)
                remove_whatever_it_is(path)
        else:
            ignore_stage_files |= files_in_stage
>           assert not files_in_stage
E           AssertionError: assert not {'spack-stage-j44yj070'}

lib/spack/spack/test/conftest.py:389: AssertionError
```

### Information on your system

The error message was taken from here:
- https://github.com/spack/spack/runs/4532065202?check_suite_focus=true

but there are many other similar cases

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
@tldahlgren fyi

Resolving patch:
diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py
--- a/lib/spack/spack/cmd/checksum.py
+++ b/lib/spack/spack/cmd/checksum.py
@@ -25,17 +25,17 @@
 
 def setup_parser(subparser):
     subparser.add_argument(
-        '--keep-stage', action='store_true',
+        '--keep-stage', action='store_true', default=False,
         help="don't clean up staging area when command completes")
     sp = subparser.add_mutually_exclusive_group()
     sp.add_argument(
-        '-b', '--batch', action='store_true',
+        '-b', '--batch', action='store_true', default=False,
         help="don't ask which versions to checksum")
     sp.add_argument(
-        '-l', '--latest', action='store_true',
+        '-l', '--latest', action='store_true', default=False,
         help="checksum the latest available version only")
     sp.add_argument(
-        '-p', '--preferred', action='store_true',
+        '-p', '--preferred', action='store_true', default=False,
         help="checksum the preferred version only")
     arguments.add_common_arguments(subparser, ['package'])
     subparser.add_argument(
diff --git a/var/spack/repos/builtin.mock/packages/preferred-test/package.py b/var/spack/repos/builtin.mock/packages/preferred-test/package.py
--- a/var/spack/repos/builtin.mock/packages/preferred-test/package.py
+++ b/var/spack/repos/builtin.mock/packages/preferred-test/package.py
@@ -7,11 +7,9 @@
 
 
 class PreferredTest(Package):
-    """Dummy package with develop version and preffered version"""
-    homepage = "http://www.openblas.net"
-    url      = "http://github.com/xianyi/OpenBLAS/archive/v0.2.15.tar.gz"
+    """Dummy package with develop version and preferred version"""
+    homepage = "https://github.com/LLNL/mpileaks"
+    url      = "https://github.com/LLNL/mpileaks/releases/download/v1.0/mpileaks-1.0.tar.gz"
 
-    version('develop', git='https://github.com/dummy/repo.git')
-    version('0.2.16', 'b1190f3d3471685f17cfd1ec1d252ac9')
-    version('0.2.15', 'b1190f3d3471685f17cfd1ec1d252ac9', preferred=True)
-    version('0.2.14', 'b1190f3d3471685f17cfd1ec1d252ac9')
+    version('develop', git='https://github.com/LLNL/mpileaks.git')
+    version('1.0', sha256='2e34cc4505556d1c1f085758e26f2f8eea0972db9382f051b2dcfb1d7d9e1825', preferred=True)


Test patch:
diff --git a/lib/spack/spack/test/cmd/audit.py b/lib/spack/spack/test/cmd/audit.py
--- a/lib/spack/spack/test/cmd/audit.py
+++ b/lib/spack/spack/test/cmd/audit.py
@@ -41,7 +41,7 @@ def test_audit_packages_https(mutable_config, mock_packages):
     assert audit.returncode == 1
 
     # This uses http and should fail
-    audit('packages-https', "preferred-test", fail_on_error=False)
+    audit('packages-https', "test-dependency", fail_on_error=False)
     assert audit.returncode == 1
 
     # providing one or more package names with https should work
diff --git a/lib/spack/spack/test/cmd/checksum.py b/lib/spack/spack/test/cmd/checksum.py
--- a/lib/spack/spack/test/cmd/checksum.py
+++ b/lib/spack/spack/test/cmd/checksum.py
@@ -30,7 +30,7 @@ def test_checksum_args(arguments, expected):
 
 
 @pytest.mark.parametrize('arguments,expected', [
-    (['--batch', 'preferred-test'], 'versions of preferred-test'),
+    (['--batch', 'preferred-test'], 'version of preferred-test'),
     (['--latest', 'preferred-test'], 'Found 1 version'),
     (['--preferred', 'preferred-test'], 'Found 1 version'),
 ])
@@ -47,7 +47,7 @@ def _get_number(*args, **kwargs):
     monkeypatch.setattr(tty, 'get_number', _get_number)
 
     output = spack_checksum('preferred-test')
-    assert 'versions of preferred-test' in output
+    assert 'version of preferred-test' in output
     assert 'version(' in output
 
 
diff --git a/lib/spack/spack/test/concretize_preferences.py b/lib/spack/spack/test/concretize_preferences.py
--- a/lib/spack/spack/test/concretize_preferences.py
+++ b/lib/spack/spack/test/concretize_preferences.py
@@ -176,16 +176,16 @@ def test_preferred_providers(self):
 
     def test_preferred(self):
         """"Test packages with some version marked as preferred=True"""
-        spec = Spec('preferred-test')
+        spec = Spec('python')
         spec.concretize()
-        assert spec.version == Version('0.2.15')
+        assert spec.version == Version('2.7.11')
 
         # now add packages.yaml with versions other than preferred
         # ensure that once config is in place, non-preferred version is used
-        update_packages('preferred-test', 'version', ['0.2.16'])
-        spec = Spec('preferred-test')
+        update_packages('python', 'version', ['3.5.0'])
+        spec = Spec('python')
         spec.concretize()
-        assert spec.version == Version('0.2.16')
+        assert spec.version == Version('3.5.0')
 
     def test_develop(self):
         """Test concretization with develop-like versions"""