1. Chris Jerdonek
  2. tox-125-randomseed

Commits

Chris Jerdonek  committed 0e65c30

Add tests for randomseed.

  • Participants
  • Parent commits 6ff87d1
  • Branches default

Comments (0)

Files changed (2)

File tests/test_config.py

View file
         config = newconfig(["-vv"], "")
         assert config.option.verbosity == 2
 
+    def test_randomseed(self, newconfig):
+        config = newconfig([], "")
+        assert config.option.randomseed is None
+        config = newconfig(["--randomseed", "100"], "")
+        assert config.option.randomseed == 100
+
     def test_substitution_jenkins_default(self, tmpdir,
                                           monkeypatch, newconfig):
         monkeypatch.setenv("HUDSON_URL", "xyz")
         p = CommandParser(cmd)
         parsed = list(p.words())
         assert parsed == ['nosetests', ' ', '-v', ' ', '-a', ' ', '!deferred', ' ', '--with-doctest', ' ', '[]']
+
+
+class TestRandomseed:
+
+    def _get_envconfig(self, newconfig, args, makeseed=None):
+        tox_ini = """
+            [testenv]
+            commands=echo {randomseed}
+        """
+        config = newconfig(args, tox_ini, makeseed=makeseed)
+        return config.envconfigs["python"]
+        
+    def test_default(self, tmpdir, newconfig):
+        envconfig = self._get_envconfig(newconfig, [])
+        cmd = envconfig.commands[0]
+        assert cmd[0] == "echo"
+        seed = int(cmd[1])  # make sure it parses to an integer
+        assert seed > 0
+
+    def test_default_explicit(self, tmpdir, newconfig):
+        makeseed = lambda: 100
+        envconfig = self._get_envconfig(newconfig, [], makeseed=makeseed)
+        assert envconfig.commands[0] == ["echo", "100"]
+
+    def test_option(self, tmpdir, newconfig):
+        envconfig = self._get_envconfig(newconfig, ["--randomseed", "200"])
+        assert envconfig.commands[0] == ["echo", "200"]

File tox/_pytestplugin.py

View file
     return "tox comes from: %r" % (tox.__file__)
 
 def pytest_funcarg__newconfig(request, tmpdir):
-    def newconfig(args, source=None):
+    def newconfig(args, source=None, makeseed=None):
         if source is None:
             source = args
             args = []
         p.write(s)
         old = tmpdir.chdir()
         try:
-            return parseconfig(args)
+            return parseconfig(args, makeseed=makeseed)
         finally:
             old.chdir()
     return newconfig