Skip to content

Commit

Permalink
backend, cli, distgit, rpmbuild: use fixture instead of deprecated yi…
Browse files Browse the repository at this point in the history
…eld_fixture

Fix fedora-copr#3351

The deprecation warning even says "Use @pytest.fixture instead; they
are the same".
  • Loading branch information
FrostyX committed Aug 23, 2024
1 parent 9bbc9d8 commit 319be9d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 47 deletions.
4 changes: 2 additions & 2 deletions backend/tests/daemons/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from copr_backend.daemons.log import RedisLogHandler


@pytest.yield_fixture
@pytest.fixture
def mc_logging():
with mock.patch("copr_backend.daemons.log.logging") as mc_logging:
yield mc_logging


@pytest.yield_fixture
@pytest.fixture
def mc_setproctitle():
with mock.patch("copr_backend.daemons.log.setproctitle") as mc_spt:
yield mc_spt
Expand Down
10 changes: 5 additions & 5 deletions backend/tests/daemons/unused_test_job_grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@

MODULE_REF = "copr_backend.daemons.job_grab"

@pytest.yield_fixture
@pytest.fixture
def mc_logging():
with mock.patch("{}.logging".format(MODULE_REF)) as mc_logging:
yield mc_logging


@pytest.yield_fixture
@pytest.fixture
def mc_setproctitle():
with mock.patch("{}.setproctitle".format(MODULE_REF)) as mc_spt:
yield mc_spt


@pytest.yield_fixture
@pytest.fixture
def mc_retask_queue():
with mock.patch("{}.jobgrabcontrol.Channel".format(MODULE_REF)) as mc_queue:
def make_queue(*args, **kwargs):
Expand All @@ -51,7 +51,7 @@ def make_queue(*args, **kwargs):
yield mc_queue


@pytest.yield_fixture
@pytest.fixture
def mc_grc():
with mock.patch("{}.get_redis_connection".format(MODULE_REF)) as handle:
yield handle
Expand Down Expand Up @@ -119,7 +119,7 @@ def teardown_method(self, method):
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)

@pytest.yield_fixture
@pytest.fixture
def mc_time(self):
with mock.patch("{}.time".format(MODULE_REF)) as mc_time:
mc_time.time.return_value = self.test_time
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/run/test_copr_prune_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
MODULE_REF = 'run.copr_prune_results'


@pytest.yield_fixture
@pytest.fixture
def mc_runcmd():
with mock.patch('{}.runcmd'.format(MODULE_REF)) as handle:
yield handle

@pytest.yield_fixture
@pytest.fixture
def mc_bcr():
with mock.patch('{}.BackendConfigReader'.format(MODULE_REF)) as handle:
yield handle

@pytest.yield_fixture
@pytest.fixture
def mc_build_devel():
with mock.patch('{}.uses_devel_repo'.format(MODULE_REF)) as handle:
yield handle

@pytest.yield_fixture
@pytest.fixture
def mc_pruner():
with mock.patch('{}.Pruner'.format(MODULE_REF)) as handle:
yield handle
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from unittest.mock import MagicMock
import pytest

@pytest.yield_fixture
@pytest.fixture
def post_req():
with mock.patch("copr_common.request.post") as obj:
yield obj
Expand All @@ -26,7 +26,7 @@ def f_request_method(request):
yield (request.param, ctx)


@pytest.yield_fixture
@pytest.fixture
def mc_time():
with mock.patch("copr_common.request.time") as obj:
yield obj
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/cli_tests_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
if six.PY3:
from unittest import mock
from unittest.mock import MagicMock
from pytest import fixture
else:
import mock
from mock import MagicMock
from pytest import yield_fixture as fixture

import pytest

config = {
"username": "jdoe",
Expand All @@ -16,7 +17,7 @@
"token": "abc",
}

@pytest.yield_fixture
@fixture
def f_test_config():
with mock.patch('copr_cli.main.config_from_file',
return_value=config) as test_config:
Expand Down
13 changes: 8 additions & 5 deletions cli/tests/test_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

import copr
# pylint: disable=unused-import
from cli_tests_lib import f_test_config
from cli_tests_lib import mock
from cli_tests_lib import config as mock_config
from cli_tests_lib import (
f_test_config,
mock,
config as mock_config,
fixture,
)
from copr_cli import main

def _main(args, capsys):
Expand Down Expand Up @@ -50,7 +53,7 @@ class TestDistGitMethodBuild(object):
}

@staticmethod
@pytest.yield_fixture
@fixture
def f_patch_create_from_distgit(f_test_config, capsys):
with mock.patch("copr.v3.proxies.build.BuildProxy.create_from_distgit") as patch:
patch.return_value = [Munch({
Expand Down Expand Up @@ -102,7 +105,7 @@ class TestDistGitMethodPackage(object):
success_stdout = "Create or edit operation was successful.\n"

@staticmethod
@pytest.yield_fixture
@fixture
def f_patch_package_distgit(f_test_config, capsys):
with mock.patch("copr.v3.proxies.package.PackageProxy.add") as p1:
with mock.patch("copr.v3.proxies.package.PackageProxy.edit") as p2:
Expand Down
5 changes: 2 additions & 3 deletions cli/tests/test_mock_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
"""

from munch import Munch
import pytest

from copr_cli import main

import six

from cli_tests_lib import mock, f_test_config
from cli_tests_lib import mock, f_test_config, fixture


class TestMockConfig():
Expand Down Expand Up @@ -77,7 +76,7 @@ def get_build_config_result(self):
"isolation": "default"
})

@pytest.yield_fixture
@fixture
def f_get_build_config(self):
method = (
'copr.v3.proxies.project_chroot.'
Expand Down
18 changes: 9 additions & 9 deletions dist-git/tests/test_crazy_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
def scriptdir():
return os.path.dirname(os.path.realpath(__file__))

@pytest.yield_fixture
@pytest.fixture
def mc_setup_git_repo():
with mock.patch("{}.setup_git_repo".format('copr_dist_git.package_import')) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_group():
with mock.patch("os.setgid") as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_chroot():
with mock.patch("os.chroot") as handle:
yield handle


@pytest.yield_fixture(scope='module')
@pytest.fixture(scope='module')
def tmpdir():
origdir = os.getcwd()
tdir = tempfile.mkdtemp()
Expand All @@ -44,15 +44,15 @@ def tmpdir():
shutil.rmtree(tdir, ignore_errors=True)


@pytest.yield_fixture
@pytest.fixture
def git_repos(tmpdir):
dirname = 'git_repos'
os.mkdir(dirname)
yield os.path.join(tmpdir, dirname)
shutil.rmtree('git_repos', ignore_errors=True)


@pytest.yield_fixture
@pytest.fixture
def origin(git_repos):
print("creating origin")
modulename = 'bob/blah/quick-package'
Expand All @@ -76,7 +76,7 @@ def origin(git_repos):
shutil.rmtree('work', ignore_errors=True)


@pytest.yield_fixture
@pytest.fixture
def branches(origin):
branches = ['f20', 'epel7', 'el6', 'fedora/26', 'rhel-7']
middle_branches = ['el6', 'fedora/26']
Expand All @@ -97,7 +97,7 @@ def branches(origin):
yield (origin, branches, middle_branches, border_branches)


@pytest.yield_fixture
@pytest.fixture
def lookaside(tmpdir):
assert 0 == os.system(
""" set -e
Expand All @@ -107,7 +107,7 @@ def lookaside(tmpdir):
shutil.rmtree('lookaside', ignore_errors=True)


@pytest.yield_fixture
@pytest.fixture
def opts_basic(tmpdir, lookaside):
class _:
pass
Expand Down
12 changes: 6 additions & 6 deletions dist-git/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@
MODULE_REF = 'copr_dist_git.importer'


@pytest.yield_fixture
@pytest.fixture
def mc_helpers():
with mock.patch("{}.helpers".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_worker():
with mock.patch("{}.Worker".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_import_package():
with mock.patch("{}.import_package".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_time():
with mock.patch("{}.time".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_get():
with mock.patch("{}.get".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_post():
with mock.patch("{}.post".format(MODULE_REF)) as handle:
yield handle
Expand Down
16 changes: 8 additions & 8 deletions dist-git/tests/test_package_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,49 @@
MODULE_REF = 'copr_dist_git.package_import'


@pytest.yield_fixture
@pytest.fixture
def mc_os_setgid():
with mock.patch("{}.os.setgid".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_subprocess_check_output():
with mock.patch("{}.subprocess.check_output".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_helpers():
with mock.patch("{}.helpers".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_shutil():
with mock.patch("{}.shutil".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_sync_branch():
with mock.patch("{}.sync_branch".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_refresh_cgit_listing():
with mock.patch("{}.refresh_cgit_listing".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_setup_git_repo():
with mock.patch("{}.setup_git_repo".format(MODULE_REF)) as handle:
yield handle


@pytest.yield_fixture
@pytest.fixture
def mc_pyrpkg_commands():
with mock.patch("{}.Commands".format(MODULE_REF)) as handle:
yield handle
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import mock
builtins = '__builtin__'

@pytest.yield_fixture
@pytest.fixture
def f_mock_calls():
p_popen = mock.patch('copr_rpmbuild.builders.mock.GentlyTimeoutedPopen')

Expand Down

0 comments on commit 319be9d

Please sign in to comment.