mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
try to improve test speed (#9136)
* tests: fix logic to gc.collect() on Windows + 3.11 * dvc.cli: cache get_main_parser() * tests: isolate environment on a session-level * bring back gc.collect()
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
from functools import lru_cache
|
||||
|
||||
from dvc import __version__
|
||||
from dvc.commands import (
|
||||
@@ -150,6 +151,7 @@ def get_parent_parser():
|
||||
return parent_parser
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_main_parser():
|
||||
parent_parser = get_parent_parser()
|
||||
|
||||
|
||||
+9
-11
@@ -174,22 +174,20 @@ def mocked_webbrowser_open(mocker):
|
||||
mocker.patch("webbrowser.open")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def isolate(tmp_path_factory, monkeypatch) -> None:
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def isolate(tmp_path_factory):
|
||||
path = tmp_path_factory.mktemp("mock")
|
||||
home_dir = path / "home"
|
||||
home_dir.mkdir()
|
||||
|
||||
monkeypatch = pytest.MonkeyPatch()
|
||||
if sys.platform == "win32":
|
||||
home_drive, home_path = os.path.splitdrive(home_dir)
|
||||
monkeypatch.setenv("USERPROFILE", str(home_dir))
|
||||
monkeypatch.setenv("HOMEDRIVE", home_drive)
|
||||
monkeypatch.setenv("HOMEPATH", home_path)
|
||||
|
||||
for env_var, sub_path in (
|
||||
("APPDATA", "Roaming"),
|
||||
("LOCALAPPDATA", "Local"),
|
||||
):
|
||||
for env_var, sub_path in (("APPDATA", "Roaming"), ("LOCALAPPDATA", "Local")):
|
||||
path = home_dir / "AppData" / sub_path
|
||||
path.mkdir(parents=True)
|
||||
monkeypatch.setenv(env_var, os.fspath(path))
|
||||
@@ -209,6 +207,8 @@ defaultBranch=master
|
||||
import pygit2
|
||||
|
||||
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir)
|
||||
yield
|
||||
monkeypatch.undo()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -247,10 +247,7 @@ def run_copy_metrics(tmp_dir, copy_script):
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def gc_collect_on_dvc_close_on_win_311(mocker):
|
||||
if sys.version_info < (3, 11) and os.name != "nt":
|
||||
return
|
||||
|
||||
def gc_collect_on_dvc_close_on_win(mocker):
|
||||
from dvc.repo import Repo
|
||||
|
||||
close = Repo.close
|
||||
@@ -259,4 +256,5 @@ def gc_collect_on_dvc_close_on_win_311(mocker):
|
||||
close(repo)
|
||||
gc.collect()
|
||||
|
||||
mocker.patch("dvc.repo.Repo.close", wrapped)
|
||||
if os.name == "nt":
|
||||
mocker.patch("dvc.repo.Repo.close", wrapped)
|
||||
|
||||
Reference in New Issue
Block a user