Repository: iterative/dvc (Python)

Issue:
Two test_info_* tests are failing on tip of master
At the [tip of master right now](https://github.com/iterative/dvc/commit/32425e90691bfd4988eb0a2d70cdc4fdba910f49), the two tests `test_info_outside_of_repo` and `test_info_in_repo` are failing for me (but not in CI, so I'm guessing this is environment-specific), because the `dvc version` output does not contain the "Filesystem type" lines that the tests are expecting.

I'm on macOS 10.14.5 and running Python 3.7.3 installed with pyenv, in a fresh virtualenv configured as specified in https://dvc.org/doc/user-guide/contributing

Cut-n-pasted output from `python -m tests`:

```
______________________________________________________________________ test_info_outside_of_repo ______________________________________________________________________
[gw2] darwin -- Python 3.7.3 /Users/gbr/.pyenv/versions/3.7.3/envs/DVC/bin/python

repo_dir = <tests.basic_env.TestDirFixture object at 0x129f640b8>, caplog = <_pytest.logging.LogCaptureFixture object at 0x129f640f0>

    def test_info_outside_of_repo(repo_dir, caplog):
        assert main(["version"]) == 0

        assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
        assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text)
        assert re.search(re.compile(r"Platform: .*"), caplog.text)
        assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
>       assert re.search(
            re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
        )
E       AssertionError: assert None
E        +  where None = <function search at 0x109ed6ea0>(re.compile('Filesystem type \\(workspace\\): .*'), 'INFO     dvc.command.version:version.py:65 DVC version: 0.53.2\n                                           Python ver...                 Platform: Darwin-18.6.0-x86_64-i386-64bit\n                                           Binary: False\n')
E        +    where <function search at 0x109ed6ea0> = re.search
E        +    and   re.compile('Filesystem type \\(workspace\\): .*') = <function compile at 0x109ed7268>('Filesystem type \\(workspace\\): .*')
E        +      where <function compile at 0x109ed7268> = re.compile
E        +    and   'INFO     dvc.command.version:version.py:65 DVC version: 0.53.2\n                                           Python ver...                 Platform: Darwin-18.6.0-x86_64-i386-64bit\n                                           Binary: False\n' = <_pytest.logging.LogCaptureFixture object at 0x129f640f0>.text

/Users/gbr/git/dvc/tests/func/test_version.py:31: AssertionError
------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------


-------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------
INFO     dvc.command.version:version.py:65 DVC version: 0.53.2
                                           Python version: 3.7.3
                                           Platform: Darwin-18.6.0-x86_64-i386-64bit
                                           Binary: False
---------------------------------------------------------------------- Captured stdout teardown -----------------------------------------------------------------------


------------------------------------------------------------------------ Captured log teardown ------------------------------------------------------------------------
DEBUG    dvc.utils:__init__.py:177 Removing '../../../../private/var/folders/_g/f_zc9wdj6vqcbsk1h62bwxmd9xsbxj/T/dvc-test.40553.vmgjwy8n.3wkYFuPE6JggPk5TfN6ZXU'
__________________________________________________________________________ test_info_in_repo __________________________________________________________________________
[gw1] darwin -- Python 3.7.3 /Users/gbr/.pyenv/versions/3.7.3/envs/DVC/bin/python

dvc_repo = Repo: '/private/var/folders/_g/f_zc9wdj6vqcbsk1h62bwxmd9xsbxj/T/dvc-test.40552.f97sqyup.brvX7Jws37VU3abAn5sjD9'
caplog = <_pytest.logging.LogCaptureFixture object at 0x1236ef5f8>

    def test_info_in_repo(dvc_repo, caplog):
        assert main(["version"]) == 0

        assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
        assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text)
        assert re.search(re.compile(r"Platform: .*"), caplog.text)
        assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
>       assert re.search(
            re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
        )
E       AssertionError: assert None
E        +  where None = <function search at 0x104e41ea0>(re.compile('Filesystem type \\(cache directory\\): .*'), 'INFO     dvc.command.version:version.py:65 DVC version: 0.53.2\n                                           Python ver...                 Platform: Darwin-18.6.0-x86_64-i386-64bit\n                                           Binary: False\n')
E        +    where <function search at 0x104e41ea0> = re.search
E        +    and   re.compile('Filesystem type \\(cache directory\\): .*') = <function compile at 0x104e42268>('Filesystem type \\(cache directory\\): .*')
E        +      where <function compile at 0x104e42268> = re.compile
E        +    and   'INFO     dvc.command.version:version.py:65 DVC version: 0.53.2\n                                           Python ver...                 Platform: Darwin-18.6.0-x86_64-i386-64bit\n                                           Binary: False\n' = <_pytest.logging.LogCaptureFixture object at 0x1236ef5f8>.text

/Users/gbr/git/dvc/tests/func/test_version.py:13: AssertionError
------------------------------------------------------------------------ Captured stdout setup ------------------------------------------------------------------------

What's next?
------------
- Check out the documentation: https://dvc.org/doc
- Get help and share ideas: https://dvc.org/chat
- Star us on GitHub: https://github.com/iterative/dvc
------------------------------------------------------------------------- Captured log setup --------------------------------------------------------------------------
INFO     dvc.repo.init:init.py:40 What's next?
------------
- Check out the documentation: https://dvc.org/doc
- Get help and share ideas: https://dvc.org/chat
- Star us on GitHub: https://github.com/iterative/dvc
------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------

DVC version: 0.53.2
Python version: 3.7.3
Platform: Darwin-18.6.0-x86_64-i386-64bit
Binary: False

-------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------
INFO     dvc.command.version:version.py:65 DVC version: 0.53.2
                                           Python version: 3.7.3
                                           Platform: Darwin-18.6.0-x86_64-i386-64bit
                                           Binary: False
---------------------------------------------------------------------- Captured stdout teardown -----------------------------------------------------------------------

DEBUG: Removing '../../../../private/var/folders/_g/f_zc9wdj6vqcbsk1h62bwxmd9xsbxj/T/dvc-test.40552.f97sqyup.brvX7Jws37VU3abAn5sjD9'
------------------------------------------------------------------------ Captured log teardown ------------------------------------------------------------------------
DEBUG    dvc.utils:__init__.py:177 Removing '../../../../private/var/folders/_g/f_zc9wdj6vqcbsk1h62bwxmd9xsbxj/T/dvc-test.40552.f97sqyup.brvX7Jws37VU3abAn5sjD9'

[...]

==== 2 failed, 619 passed, 41 skipped, 10 warnings in 73.48 seconds ====
```


Discussion:
Hi @gthb !

Run `pip install psutil` and it should fix it :) Sorry for such a cryptic thing, this is a workaround for https://github.com/iterative/dvc/issues/2284 . We should really add `skipif(psutil is None)` or something for those tests. I'll adjust them in a second.

Thanks for the feedback! :slightly_smiling_face: 



Patch:
diff --git a/dvc/command/version.py b/dvc/command/version.py
index d964eaa8b1..770d9ad3c9 100644
--- a/dvc/command/version.py
+++ b/dvc/command/version.py
@@ -42,22 +42,22 @@ def run(self):
             binary=binary,
         )
 
-        if psutil:
-            try:
-                repo = Repo()
-                root_directory = repo.root_dir
+        try:
+            repo = Repo()
+            root_directory = repo.root_dir
+
+            info += "Cache: {cache}\n".format(
+                cache=self.get_linktype_support_info(repo)
+            )
 
+            if psutil:
                 info += (
-                    "Cache: {cache}\n"
                     "Filesystem type (cache directory): {fs_cache}\n"
-                ).format(
-                    cache=self.get_linktype_support_info(repo),
-                    fs_cache=self.get_fs_type(repo.cache.local.cache_dir),
-                )
-
-            except NotDvcRepoError:
-                root_directory = os.getcwd()
+                ).format(fs_cache=self.get_fs_type(repo.cache.local.cache_dir))
+        except NotDvcRepoError:
+            root_directory = os.getcwd()
 
+        if psutil:
             info += ("Filesystem type (workspace): {fs_root}").format(
                 fs_root=self.get_fs_type(os.path.abspath(root_directory))
             )


Test patch:
diff --git a/tests/func/test_version.py b/tests/func/test_version.py
index a040c1e145..d0fe6f2eb4 100644
--- a/tests/func/test_version.py
+++ b/tests/func/test_version.py
@@ -1,6 +1,8 @@
 import re
+import pytest
 
 from dvc.main import main
+from dvc.command.version import psutil
 
 
 def test_info_in_repo(dvc_repo, caplog):
@@ -11,13 +13,19 @@ def test_info_in_repo(dvc_repo, caplog):
     assert re.search(re.compile(r"Platform: .*"), caplog.text)
     assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
     assert re.search(
-        re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
+        re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
     )
+
+
+@pytest.mark.skipif(psutil is None, reason="No psutil.")
+def test_fs_info_in_repo(dvc_repo, caplog):
+    assert main(["version"]) == 0
+
     assert re.search(
-        re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
+        re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
     )
     assert re.search(
-        re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
+        re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
     )
 
 
@@ -28,12 +36,18 @@ def test_info_outside_of_repo(repo_dir, caplog):
     assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text)
     assert re.search(re.compile(r"Platform: .*"), caplog.text)
     assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
+    assert not re.search(
+        re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
+    )
+
+
+@pytest.mark.skipif(psutil is None, reason="No psutil.")
+def test_fs_info_outside_of_repo(repo_dir, caplog):
+    assert main(["version"]) == 0
+
     assert re.search(
         re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
     )
     assert not re.search(
         re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
     )
-    assert not re.search(
-        re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
-    )