Repository: AcademySoftwareFoundation/rez (language: python)

Issue:
rez-env output test is not testing on specified shell
In test case `test_shells.TestShells.test_rez_env_output`, it uses decorator `per_available_shell`, which iterates all available shells and use `config.override` to set testing target.

https://github.com/nerdvegas/rez/blob/8f965f6ed7ac438c1ea331940e6ad14f766564fa/src/rez/tests/util.py#L218-L221

However, when testing `rez-env` output, subprocess is called which actually won't take the config override and always testing on system default shell.

https://github.com/nerdvegas/rez/blob/8f965f6ed7ac438c1ea331940e6ad14f766564fa/src/rez/tests/test_shells.py#L183-L190

The var `arg` in above code should changed into
```python
   ...
     def _test(txt): 
         ...
         args = [binpath, "--shell", config.default_shell, "--", "echo", txt]
```

I found this issue when I was tweaking code in CMD shell class and somehow the test result of PowerShell also gets affected and made me confused.



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml
index 69266ac57..29ad76fe8 100644
--- a/.github/workflows/ubuntu.yaml
+++ b/.github/workflows/ubuntu.yaml
@@ -25,8 +25,8 @@ jobs:
     strategy:
       matrix:
         os-version:
-          - '16.04'
           - '18.04'
+          - '20.04'
         python-version:
           - '2.7'
           - '3.6'


Test patch:
diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py
index 28f56e57d..b170f6733 100644
--- a/src/rez/tests/test_shells.py
+++ b/src/rez/tests/test_shells.py
@@ -11,6 +11,7 @@
 from rez.tests.util import TestBase, TempdirMixin, per_available_shell, \
     install_dependent
 from rez.bind import hello_world
+from rez.config import config
 import unittest
 import subprocess
 import tempfile
@@ -180,19 +181,23 @@ def test_rcfile(self):
             self.assertEqual(_stdout(p), "Hello Rez World!")
             os.remove(path)
 
-    @per_available_shell()
+    @per_available_shell(exclude=["cmd", "powershell", "pwsh", "csh", "tcsh"])
     @install_dependent()
     def test_rez_env_output(self):
+        target_shell = config.default_shell  # overridden by test util
+
         def _test(txt):
             # Assumes that the shell has an echo command, build-in or alias
             binpath = os.path.join(system.rez_bin_path, "rez-env")
-            args = [binpath, "--", "echo", txt]
+            args = [binpath, "--shell", target_shell, "--", "echo", txt]
 
             process = subprocess.Popen(
                 args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE, universal_newlines=True
             )
             sh_out = process.communicate()
+            if sh_out[1]:
+                raise Exception("Command %r failed:\n%s" % (txt, sh_out[1]))
             self.assertEqual(sh_out[0].strip(), txt)
 
         # please note - it's no coincidence that there are no substrings like
diff --git a/src/rez/tests/util.py b/src/rez/tests/util.py
index 66a678627..42c988fa9 100644
--- a/src/rez/tests/util.py
+++ b/src/rez/tests/util.py
@@ -198,8 +198,10 @@ def wrapper(self, *args, **kwargs):
     return decorator
 
 
-def per_available_shell():
+def per_available_shell(exclude=None):
     """Function decorator that runs the function over all available shell types."""
+    exclude = exclude or []
+
     def decorator(func):
         @functools.wraps(func)
         def wrapper(self, *args, **kwargs):
@@ -216,6 +218,10 @@ def wrapper(self, *args, **kwargs):
             ]
 
             for shell in shells:
+                if not only_shell and shell in exclude:
+                    print("\nshell excluded from this test: %s..." % shell)
+                    continue
+
                 print("\ntesting in shell: %s..." % shell)
                 config.override("default_shell", shell)