Don't crash with --pyargs and a filename that looks like a modu… (#5503)
Don't crash with --pyargs and a filename that looks like a module
This commit is contained in:
		
						commit
						65fbdf2568
					
				|  | @ -631,7 +631,10 @@ class Session(nodes.FSCollector): | ||||||
|         """Convert a dotted module name to path.""" |         """Convert a dotted module name to path.""" | ||||||
|         try: |         try: | ||||||
|             spec = importlib.util.find_spec(x) |             spec = importlib.util.find_spec(x) | ||||||
|         except (ValueError, ImportError): |         # AttributeError: looks like package module, but actually filename | ||||||
|  |         # ImportError: module does not exist | ||||||
|  |         # ValueError: not a module name | ||||||
|  |         except (AttributeError, ImportError, ValueError): | ||||||
|             return x |             return x | ||||||
|         if spec is None or spec.origin in {None, "namespace"}: |         if spec is None or spec.origin in {None, "namespace"}: | ||||||
|             return x |             return x | ||||||
|  |  | ||||||
|  | @ -646,6 +646,12 @@ class TestInvocationVariants: | ||||||
|         # should only configure once |         # should only configure once | ||||||
|         assert result.outlines.count("configuring") == 1 |         assert result.outlines.count("configuring") == 1 | ||||||
| 
 | 
 | ||||||
|  |     def test_pyargs_filename_looks_like_module(self, testdir): | ||||||
|  |         testdir.tmpdir.join("conftest.py").ensure() | ||||||
|  |         testdir.tmpdir.join("t.py").write("def test(): pass") | ||||||
|  |         result = testdir.runpytest("--pyargs", "t.py") | ||||||
|  |         assert result.ret == ExitCode.OK | ||||||
|  | 
 | ||||||
|     def test_cmdline_python_package(self, testdir, monkeypatch): |     def test_cmdline_python_package(self, testdir, monkeypatch): | ||||||
|         import warnings |         import warnings | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue