terminal: fix crash in header reporting when absolute testpaths is used
Regressed in 6.1.0 in 62e249a1f9.
The `x` is an `str` but is expected to be a `pathlib.Path`. Not caught
by mypy because `config.getini()` returns `Any`.
Fix by just removing the `bestrelpath` call:
- testpaths are always relative to the rootdir, it thus would be very
  unusual to specify an absolute path there.
- The code was wrong even before the regression: `py.path.local`'s
  `bestrelpath` function expects a `py.path.local`, not an `str`. But it
  had some weird `try ... except AttributeError` fallback which just
  returns the argument, i.e. it was a no-op. So there is no behavior
  change.
- It seems reasonable to me to just print the full path if that's what
  the ini specifies.
			
			
This commit is contained in:
		
							parent
							
								
									db08c7fbb0
								
							
						
					
					
						commit
						61f80a783a
					
				| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
Fixed crash in header reporting when :confval:`testpaths` is used and contains absolute paths (regression in 6.1.0).
 | 
			
		||||
| 
						 | 
				
			
			@ -718,10 +718,10 @@ class TerminalReporter:
 | 
			
		|||
        if config.inipath:
 | 
			
		||||
            line += ", configfile: " + bestrelpath(config.rootpath, config.inipath)
 | 
			
		||||
 | 
			
		||||
        testpaths = config.getini("testpaths")
 | 
			
		||||
        testpaths = config.getini("testpaths")  # type: List[str]
 | 
			
		||||
        if testpaths and config.args == testpaths:
 | 
			
		||||
            rel_paths = [bestrelpath(config.rootpath, x) for x in testpaths]
 | 
			
		||||
            line += ", testpaths: {}".format(", ".join(rel_paths))
 | 
			
		||||
            line += ", testpaths: {}".format(", ".join(testpaths))
 | 
			
		||||
 | 
			
		||||
        result = [line]
 | 
			
		||||
 | 
			
		||||
        plugininfo = config.pluginmanager.list_plugin_distinfo()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ import pytest
 | 
			
		|||
from _pytest._io.wcwidth import wcswidth
 | 
			
		||||
from _pytest.config import Config
 | 
			
		||||
from _pytest.config import ExitCode
 | 
			
		||||
from _pytest.monkeypatch import MonkeyPatch
 | 
			
		||||
from _pytest.pathlib import Path
 | 
			
		||||
from _pytest.pytester import Testdir
 | 
			
		||||
from _pytest.reports import BaseReport
 | 
			
		||||
| 
						 | 
				
			
			@ -749,6 +750,29 @@ class TestTerminalFunctional:
 | 
			
		|||
        result = testdir.runpytest("tests")
 | 
			
		||||
        result.stdout.fnmatch_lines(["rootdir: *test_header0, configfile: tox.ini"])
 | 
			
		||||
 | 
			
		||||
    def test_header_absolute_testpath(
 | 
			
		||||
        self, testdir: Testdir, monkeypatch: MonkeyPatch
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        """Regresstion test for #7814."""
 | 
			
		||||
        tests = testdir.tmpdir.join("tests")
 | 
			
		||||
        tests.ensure_dir()
 | 
			
		||||
        testdir.makepyprojecttoml(
 | 
			
		||||
            """
 | 
			
		||||
            [tool.pytest.ini_options]
 | 
			
		||||
            testpaths = ['{}']
 | 
			
		||||
        """.format(
 | 
			
		||||
                tests
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        result = testdir.runpytest()
 | 
			
		||||
        result.stdout.fnmatch_lines(
 | 
			
		||||
            [
 | 
			
		||||
                "rootdir: *absolute_testpath0, configfile: pyproject.toml, testpaths: {}".format(
 | 
			
		||||
                    tests
 | 
			
		||||
                )
 | 
			
		||||
            ]
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_no_header(self, testdir):
 | 
			
		||||
        testdir.tmpdir.join("tests").ensure_dir()
 | 
			
		||||
        testdir.tmpdir.join("gui").ensure_dir()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue