Bug 1517621 - [tryselect] Mock out entire vcs object in python tests, r=jmaher
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 04 Jan 2019 10:40:35 +0000
changeset 509650 165704210c3f00629f0e4a148f75c1b9e5160231
parent 509649 13be012a1bae66047edf1e12ad371ff2e7f81712
child 509651 5f6139ef7c2cc63904a73d6fe8b52031a295784d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1517621
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517621 - [tryselect] Mock out entire vcs object in python tests, r=jmaher Differential Revision: https://phabricator.services.mozilla.com/D15695
tools/tryselect/test/conftest.py
--- a/tools/tryselect/test/conftest.py
+++ b/tools/tryselect/test/conftest.py
@@ -1,40 +1,38 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
+import pytest
+from mock import MagicMock
 from moztest.resolve import TestResolver
-from mozversioncontrol import HgRepository, GitRepository
-import pytest
+
+from tryselect import push
 
 
 @pytest.fixture
 def patch_resolver(monkeypatch):
     def inner(suites, tests):
         def fake_test_metadata(*args, **kwargs):
             return suites, tests
         monkeypatch.setattr(TestResolver, 'resolve_metadata', fake_test_metadata)
     return inner
 
 
 @pytest.fixture(autouse=True)
-def patch_vcs(monkeypatch, tmpdir):
-    # Make sure we don't accidentally push to try
-    def fake_push_to_try(*args, **kwargs):
-        pass
-
-    def fake_working_directory_clean(*args, **kwargs):
-        return True
-
-    for cls in (HgRepository, GitRepository):
-        monkeypatch.setattr(cls, 'push_to_try', fake_push_to_try)
-        monkeypatch.setattr(cls, 'working_directory_clean', fake_working_directory_clean)
+def patch_vcs(monkeypatch):
+    attrs = {
+        'path': push.vcs.path,
+    }
+    mock = MagicMock()
+    mock.configure_mock(**attrs)
+    monkeypatch.setattr(push, 'vcs', mock)
 
 
 def pytest_generate_tests(metafunc):
     if all(fixture in metafunc.fixturenames for fixture in ('template', 'args', 'expected')):
         def load_tests():
             for template, tests in metafunc.module.TEMPLATE_TESTS.items():
                 for args, expected in tests:
                     yield (template, args, expected)