Commits

holger krekel  committed 8d323c8

introduce white list for commands

  • Participants
  • Parent commits bb8cfbe

Comments (0)

Files changed (9)

 1.5.0.dev
 -----------------
 
+- re-fix issue2 - add command_whitelist to be used in ``[testenv*]``
+  sections, allowing to avoid warnings for commands such as ``make``,
+  used from the commands value.
+
 - fix issue97 - allow substitutions to reference from other sections
   (thanks Krisztian Fekete)
 

File doc/config.txt

     For eventually performing a call to ``subprocess.Popen(args, ...)``
     ``args`` are determined by splitting the whole command by whitespace.
 
+.. confval:: whitelist_externals=MULTI-LINE-LIST
+
+    each line specifies a command name (in glob-style pattern format)
+    which can be used in the ``commands`` section without triggering
+    a "not installed in virtualenv" warning.  Example: if you use the 
+    unix ``make`` for running tests you can list ``whitelist_externals=make``
+    or ``whitelist_externals=/usr/bin/make`` if you want more precision.
+    If you don't want tox to issue a warning in any case, just use
+   ``whitelist_externals=*`` which will match all commands (not recommended).
+
 .. confval:: changedir=path
 
     change to this working directory when executing the test command.
         description='virtualenv-based automation of test activities',
         long_description=long_description,
         url='http://tox.testrun.org/',
-        version='1.5.dev8',
+        version='1.5.dev9',
         license='http://opensource.org/licenses/MIT',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
         author='holger krekel',

File tests/test_config.py

         envconfig = config.envconfigs['py']
         assert envconfig.commands == [["abc"]]
 
+    def test_whitelist_externals(self, tmpdir, newconfig):
+        config = newconfig("""
+            [testenv]
+            whitelist_externals = xyz
+            commands=xyz
+            [testenv:x]
+
+            [testenv:py]
+            whitelist_externals = xyz2
+            commands=abc
+        """)
+        assert len(config.envconfigs) == 2
+        envconfig = config.envconfigs['py']
+        assert envconfig.commands == [["abc"]]
+        assert envconfig.whitelist_externals == ["xyz2"]
+        envconfig = config.envconfigs['x']
+        assert envconfig.whitelist_externals == ["xyz"]
+
     def test_changedir(self, tmpdir, newconfig):
         config = newconfig("""
             [testenv]

File tests/test_venv.py

     mocksession.report.expect("warning", "*test command found but not*")
     assert venv.status == "commands failed"
 
+def test_install_command_whitelisted(newmocksession, monkeypatch):
+    mocksession = newmocksession(['--recreate'], """
+        [testenv]
+        whitelist_externals = py.test
+                              xy*
+        commands=
+            py.test
+            xyz
+    """)
+    venv = mocksession.getenv('python')
+    venv.test()
+    mocksession.report.expect("warning", "*test command found but not*",
+                              invert=True)
+    assert venv.status == "commands failed"
+
 @pytest.mark.skipif("not sys.platform.startswith('linux')")
 def test_install_command_not_installed(newmocksession):
     mocksession = newmocksession(['--recreate'], """

File tox/__init__.py

 #
-__version__ = '1.5.dev8'
+__version__ = '1.5.dev9'
 
 class exception:
     class Error(Exception):

File tox/_config.py

             vc.setenv = None
 
         vc.commands = reader.getargvlist(section, "commands")
+        vc.whitelist_externals = reader.getlist(section,
+                                                "whitelist_externals")
         vc.deps = []
         for depline in reader.getlist(section, "deps"):
             m = re.match(r":(\w+):\s*(\S+)", depline)

File tox/_venv.py

         if p.relto(self.envconfig.envdir):
             return p
         if venv:
-            self.session.report.warning(
-                "test command found but not installed in testenv\n"
-                "  cmd: %s\n"
-                "  env: %s\n"
-                "Maybe forgot to specify a dependency?" % (p,
-                self.envconfig.envdir))
+            for x in self.envconfig.whitelist_externals:
+                if p.fnmatch(x):
+                    break
+            else:
+                self.session.report.warning(
+                    "test command found but not installed in testenv\n"
+                    "  cmd: %s\n"
+                    "  env: %s\n"
+                    "Maybe forgot to specify a dependency?" % (p,
+                    self.envconfig.envdir))
         return str(p) # will not be rewritten for reporting
 
     def _ispython3(self):

File toxbootstrap.py

 
 """
 
-__version__ = '1.5.dev8'
+__version__ = '1.5.dev9'
 
 import sys
 import os