From e470d93196bb4034d0a4b6914365a82d6c59e35e Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 11 Feb 2021 18:23:12 +0000 Subject: [PATCH] Fix test_find_sources when run under site-packages (#10075) This was failing during wheel builds because we run the tests after installation (under `site-packages`), and this confused the module search logic. Hard code the paths to make this work in any install location. --- mypy/test/test_find_sources.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mypy/test/test_find_sources.py b/mypy/test/test_find_sources.py index 056ddf13b108..6d66a28f4e2d 100644 --- a/mypy/test/test_find_sources.py +++ b/mypy/test/test_find_sources.py @@ -1,12 +1,15 @@ -from mypy.modulefinder import BuildSource import os import pytest +import shutil +import tempfile import unittest from typing import List, Optional, Set, Tuple + from mypy.find_sources import InvalidSourceList, SourceFinder, create_source_list from mypy.fscache import FileSystemCache from mypy.modulefinder import BuildSource from mypy.options import Options +from mypy.modulefinder import BuildSource class FakeFSCache(FileSystemCache): @@ -60,6 +63,15 @@ def find_sources( class SourceFinderSuite(unittest.TestCase): + def setUp(self) -> None: + self.tempdir = tempfile.mkdtemp() + self.oldcwd = os.getcwd() + os.chdir(self.tempdir) + + def tearDown(self) -> None: + os.chdir(self.oldcwd) + shutil.rmtree(self.tempdir) + def test_crawl_no_namespace(self) -> None: options = Options() options.namespace_packages = False