From a4b55a00ecc9d9b75b120f86b5eca71b79bba020 Mon Sep 17 00:00:00 2001 From: pawel Date: Tue, 14 Jan 2020 14:45:26 +0100 Subject: [PATCH 1/4] conftest: remove dvc_repo, erepo, git, git_erepo --- tests/conftest.py | 79 +---------------------------------------------- 1 file changed, 1 insertion(+), 78 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7ae4ed571c..e147ca7eb5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,12 +2,9 @@ import mockssh import pytest -from git import Repo -from git.exc import GitCommandNotFound from dvc.remote.ssh.connection import SSHConnection -from dvc.repo import Repo as DvcRepo -from .basic_env import TestDirFixture, TestDvcGitFixture, TestGitFixture +from .basic_env import TestDirFixture from .dir_helpers import * # noqa @@ -42,38 +39,6 @@ def repo_dir(): old_fixture.tearDown() -# NOTE: this duplicates code from GitFixture, -# would fix itself once class-based fixtures are removed -@pytest.fixture -def git(repo_dir): - # NOTE: handles EAGAIN error on BSD systems (osx in our case). - # Otherwise when running tests you might get this exception: - # - # GitCommandNotFound: Cmd('git') not found due to: - # OSError('[Errno 35] Resource temporarily unavailable') - retries = 5 - while True: - try: - git = Repo.init() - break - except GitCommandNotFound: - retries -= 1 - if not retries: - raise - - try: - git.index.add([repo_dir.CODE]) - git.index.commit("add code") - yield git - finally: - git.close() - - -@pytest.fixture -def dvc_repo(repo_dir): - yield DvcRepo.init(repo_dir._root_dir, no_scm=True) - - here = os.path.abspath(os.path.dirname(__file__)) user = "user" @@ -98,51 +63,9 @@ def ssh(ssh_server): yield SSHConnection(**ssh_server.test_creds) -@pytest.fixture -def erepo(repo_dir): - repo = TestDvcGitFixture() - repo.setUp() - try: - stage_foo = repo.dvc.add(repo.FOO)[0] - stage_bar = repo.dvc.add(repo.BAR)[0] - stage_data_dir = repo.dvc.add(repo.DATA_DIR)[0] - repo.dvc.scm.add([stage_foo.path, stage_bar.path, stage_data_dir.path]) - repo.dvc.scm.commit("init repo") - - repo.create("version", "master") - repo.dvc.add("version") - repo.dvc.scm.add([".gitignore", "version.dvc"]) - repo.dvc.scm.commit("master") - - repo.dvc.scm.checkout("branch", create_new=True) - os.unlink(os.path.join(repo.root_dir, "version")) - repo.create("version", "branch") - repo.dvc.add("version") - repo.dvc.scm.add([".gitignore", "version.dvc"]) - repo.dvc.scm.commit("branch") - - repo.dvc.scm.checkout("master") - - repo.dvc.scm.close() - repo.git.close() - - os.chdir(repo._saved_dir) - yield repo - finally: - repo.tearDown() - - @pytest.fixture(scope="session", autouse=True) def _close_pools(): from dvc.remote.pool import close_pools yield close_pools() - - -@pytest.fixture -def git_erepo(): - repo = TestGitFixture() - repo.setUp() - yield repo - repo.tearDown() From c2f5e35f1d42461dd0e6682598007e17435de4a7 Mon Sep 17 00:00:00 2001 From: pawel Date: Tue, 14 Jan 2020 15:52:33 +0100 Subject: [PATCH 2/4] conftest: remove repo_dir --- tests/conftest.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e147ca7eb5..6e01739aac 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ import pytest from dvc.remote.ssh.connection import SSHConnection -from .basic_env import TestDirFixture from .dir_helpers import * # noqa @@ -28,17 +27,6 @@ def reset_loglevel(request, caplog): yield -# Wrap class like fixture as pytest-like one to avoid code duplication -@pytest.fixture -def repo_dir(): - old_fixture = TestDirFixture() - old_fixture.setUp() - try: - yield old_fixture - finally: - old_fixture.tearDown() - - here = os.path.abspath(os.path.dirname(__file__)) user = "user" From 18446996ab9380657e64fa81fe9bdceb324b05a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Thu, 16 Jan 2020 10:43:13 +0100 Subject: [PATCH 3/4] get: tes_get_from_non_dvc_master: capture git logs at INFO --- tests/func/test_get.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/func/test_get.py b/tests/func/test_get.py index cdbbe4bbdd..d7b272e26e 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -174,7 +174,9 @@ def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog): caplog.clear() dst = "file_imported" - with caplog.at_level(logging.INFO, logger="dvc"): + with caplog.at_level(logging.INFO, logger="dvc"), caplog.at_level( + logging.INFO, logger="git" + ): Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="branch") assert caplog.text == "" From 36c64c66db258690265a9c0c7a2a4cb9f63fabd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Thu, 16 Jan 2020 11:09:35 +0100 Subject: [PATCH 4/4] test_get_from_non_dvc_master: add comment about git logs --- tests/func/test_get.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/func/test_get.py b/tests/func/test_get.py index d7b272e26e..c6bd1adaa7 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -174,8 +174,11 @@ def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog): caplog.clear() dst = "file_imported" - with caplog.at_level(logging.INFO, logger="dvc"), caplog.at_level( - logging.INFO, logger="git" + + # removing `git` import in conftest resulted in unexpected logs from + # that package, see https://github.com/iterative/dvc/issues/3167 + with caplog.at_level(logging.INFO, logger="git"), caplog.at_level( + logging.INFO, logger="dvc" ): Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="branch")