refactor: switch from mock to unittest.mock (#34844)
As of Python 3.3, the 3rd-party `mock` package has been subsumed into the standard `unittest.mock` package. Refactoring tests to use the latter will allow us to drop `mock` as a dependency, which is currently coming in transitively through requirements/edx/paver.in. We don't actually drop the `mock` dependency in this PR. That will happen naturally in: * https://github.com/openedx/edx-platform/pull/34830
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
"""
|
||||
Test the get_learners_to_retire.py script
|
||||
"""
|
||||
from unittest.mock import DEFAULT, patch
|
||||
|
||||
import os
|
||||
|
||||
from click.testing import CliRunner
|
||||
from mock import DEFAULT, patch
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
from scripts.user_retirement.get_learners_to_retire import get_learners_to_retire
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
Test the retire_one_learner.py script
|
||||
"""
|
||||
from unittest.mock import DEFAULT, patch
|
||||
|
||||
from click.testing import CliRunner
|
||||
from mock import DEFAULT, patch
|
||||
|
||||
from scripts.user_retirement.retire_one_learner import (
|
||||
END_STATES,
|
||||
|
||||
@@ -4,12 +4,12 @@ Test the retirement_archive_and_cleanup.py script
|
||||
|
||||
import datetime
|
||||
import os
|
||||
from unittest.mock import DEFAULT, call, patch
|
||||
|
||||
import boto3
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
from click.testing import CliRunner
|
||||
from mock import DEFAULT, call, patch
|
||||
from moto import mock_ec2, mock_s3
|
||||
|
||||
from scripts.user_retirement.retirement_archive_and_cleanup import (
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
Test the retirement_bulk_status_update.py script
|
||||
"""
|
||||
from unittest.mock import DEFAULT, patch
|
||||
|
||||
from click.testing import CliRunner
|
||||
from mock import DEFAULT, patch
|
||||
|
||||
from scripts.user_retirement.retirement_bulk_status_update import (
|
||||
ERR_BAD_CONFIG,
|
||||
|
||||
@@ -8,9 +8,9 @@ import os
|
||||
import time
|
||||
import unicodedata
|
||||
from datetime import date
|
||||
from unittest.mock import DEFAULT, patch
|
||||
|
||||
from click.testing import CliRunner
|
||||
from mock import DEFAULT, patch
|
||||
from six import PY2, itervalues
|
||||
|
||||
from scripts.user_retirement.retirement_partner_report import \
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
Tests for edX API calls.
|
||||
"""
|
||||
import unittest
|
||||
from unittest.mock import DEFAULT, patch
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import requests
|
||||
import responses
|
||||
from ddt import data, ddt, unpack
|
||||
from mock import DEFAULT, patch
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
from responses import GET, PATCH, POST, matchers
|
||||
from responses.registries import OrderedRegistry
|
||||
|
||||
@@ -6,11 +6,11 @@ import json
|
||||
import re
|
||||
import unittest
|
||||
from itertools import islice
|
||||
from unittest.mock import Mock, call, mock_open, patch
|
||||
|
||||
import backoff
|
||||
import ddt
|
||||
import requests_mock
|
||||
from mock import Mock, call, mock_open, patch
|
||||
|
||||
import scripts.user_retirement.utils.jenkins as jenkins
|
||||
from scripts.user_retirement.utils.exception import BackendError
|
||||
|
||||
@@ -3,8 +3,8 @@ Tests for the Salesforce API functionality
|
||||
"""
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from simple_salesforce import SalesforceError
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
Tests for the Segment API functionality
|
||||
"""
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import requests
|
||||
from six import text_type
|
||||
|
||||
Reference in New Issue
Block a user