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:
@@ -6,12 +6,11 @@ Tests of the Capa XModule
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import mock
|
||||
import os
|
||||
import random
|
||||
import textwrap
|
||||
import unittest
|
||||
from unittest.mock import DEFAULT, Mock, patch
|
||||
from unittest.mock import DEFAULT, Mock, PropertyMock, patch
|
||||
|
||||
import pytest
|
||||
import ddt
|
||||
@@ -820,7 +819,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Disabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=False
|
||||
):
|
||||
# First Attempt
|
||||
@@ -846,7 +845,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Enabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
# Third Attempt
|
||||
@@ -887,7 +886,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Enabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
# First Attempt
|
||||
@@ -913,7 +912,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Disabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=False
|
||||
):
|
||||
# Third Attempt
|
||||
@@ -1636,7 +1635,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Disabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=False
|
||||
):
|
||||
# Score is the last score
|
||||
@@ -1652,12 +1651,12 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Enabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
with patch(
|
||||
'xmodule.capa.capa_problem.LoncapaProblem.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
# Change grading method to 'first_score'
|
||||
@@ -1706,12 +1705,12 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Enabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
with patch(
|
||||
'xmodule.capa.capa_problem.LoncapaProblem.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=True
|
||||
):
|
||||
# Grading method is 'last_score'
|
||||
@@ -1745,7 +1744,7 @@ class ProblemBlockTest(unittest.TestCase): # lint-amnesty, pylint: disable=miss
|
||||
# Disabled grading method
|
||||
with patch(
|
||||
'xmodule.capa_block.ProblemBlock.is_grading_method_enabled',
|
||||
new_callable=mock.PropertyMock,
|
||||
new_callable=PropertyMock,
|
||||
return_value=False
|
||||
):
|
||||
block.rescore(only_if_higher=False)
|
||||
|
||||
Reference in New Issue
Block a user