Commits

Anonymous committed 92c486f

Update to detect session type and top dir for latest pytest.

Also remove reading coverage config file.

Comments (0)

Files changed (2)

         cov_report = session.config.getvalue('cov_report') or ['term']
         cov_config = session.config.getvalue('cov_config')
 
-        name_to_cls = dict(Session=cov_core.Central,
-                           DSession=cov_core.DistMaster,
-                           SlaveSession=cov_core.DistSlave)
         session_name = session.__class__.__name__
-        controller_cls = name_to_cls.get(session_name, cov_core.Central)
+        is_master = (session.config.pluginmanager.hasplugin('dsession') or
+                     session_name == 'DSession')
+        is_slave = (hasattr(session.config, 'slaveinput') or
+                    session_name == 'SlaveSession')
+        nodeid = None
+
+        if is_master:
+            controller_cls = cov_core.DistMaster
+        elif is_slave:
+            controller_cls = cov_core.DistSlave
+            nodeid = session.config.slaveinput.get('slaveid', getattr(session, 'nodeid'))
+        else:
+            controller_cls = cov_core.Central
+
         self.cov_controller = controller_cls(cov_source,
                                              cov_report,
                                              cov_config,
                                              session.config,
-                                             getattr(session, 'nodeid', None))
+                                             nodeid)
 
         self.cov_controller.start()
 

test_pytest_cov.py

 def test_central(testdir):
     script = testdir.makepyfile(SCRIPT)
 
-    result = testdir.runpytest(script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % script.dirpath(),
-                               '--cov-report=term-missing')
+                               '--cov-report=term-missing',
+                               script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
 def test_dist_collocated(testdir):
     script = testdir.makepyfile(SCRIPT)
 
-    result = testdir.runpytest(script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % script.dirpath(),
                                '--cov-report=term-missing',
                                '--dist=load',
-                               '--tx=2*popen')
+                               '--tx=2*popen',
+                               script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
     dir1 = testdir.mkdir('dir1')
     dir2 = testdir.mkdir('dir2')
 
-    result = testdir.runpytest(script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % script.dirpath(),
                                '--cov-report=term-missing',
                                '--dist=load',
                                '--tx=popen//chdir=%s' % dir1,
                                '--tx=popen//chdir=%s' % dir2,
-                               '--rsyncdir=%s' % script.basename)
+                               '--rsyncdir=%s' % script.basename,
+                               script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
     scripts = testdir.makepyfile(parent_script=SCRIPT_PARENT, child_script=SCRIPT_CHILD)
     parent_script = scripts.dirpath().join('parent_script.py')
 
-    result = testdir.runpytest(parent_script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % scripts.dirpath(),
-                               '--cov-report=term-missing')
+                               '--cov-report=term-missing',
+                               parent_script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
     scripts = testdir.makepyfile(parent_script=SCRIPT_PARENT, child_script=SCRIPT_CHILD)
     parent_script = scripts.dirpath().join('parent_script.py')
 
-    result = testdir.runpytest(parent_script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % scripts.dirpath(),
                                '--cov-report=term-missing',
                                '--dist=load',
-                               '--tx=2*popen')
+                               '--tx=2*popen',
+                               parent_script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
     dir1 = tmpdir.mkdir('dir1')
     dir2 = tmpdir.mkdir('dir2')
 
-    result = testdir.runpytest(parent_script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % scripts.dirpath(),
                                '--cov-report=term-missing',
                                '--dist=load',
                                '--tx=popen//chdir=%s' % dir1,
                                '--tx=popen//chdir=%s' % dir2,
                                '--rsyncdir=%s' % child_script,
-                               '--rsyncdir=%s' % parent_script)
+                               '--rsyncdir=%s' % parent_script,
+                               parent_script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
 def test_empty_report(testdir):
     script = testdir.makepyfile(SCRIPT)
 
-    result = testdir.runpytest(script,
+    result = testdir.runpytest('-v',
                                '--cov=non_existent_module',
-                               '--cov-report=term-missing')
+                               '--cov-report=term-missing',
+                               script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: platform *, python * -*',
 
     script = testdir.makepyfile(SCRIPT)
 
-    result = testdir.runpytest(script,
+    result = testdir.runpytest('-v',
                                '--cov=%s' % script.dirpath(),
                                '--cov-report=term-missing',
                                '--dist=load',
-                               '--tx=popen//python=/usr/local/python255-empty/bin/python')
+                               '--tx=popen//python=/usr/local/python255-empty/bin/python',
+                               script)
 
     result.stdout.fnmatch_lines([
             '*- coverage: failed slaves -*'