[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
e210fe4676
commit
0803d38a6c
|
@ -1237,7 +1237,6 @@ If the data created by the factory requires managing, the fixture can take care
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def make_customer_record():
|
def make_customer_record():
|
||||||
|
|
||||||
created_records = []
|
created_records = []
|
||||||
|
|
||||||
def _make_customer_record(name):
|
def _make_customer_record(name):
|
||||||
|
|
|
@ -135,10 +135,10 @@ This can be done in our test file by defining a class to represent ``r``.
|
||||||
# this is the previous code block example
|
# this is the previous code block example
|
||||||
import app
|
import app
|
||||||
|
|
||||||
|
|
||||||
# custom class to be the mock return value
|
# custom class to be the mock return value
|
||||||
# will override the requests.Response returned from requests.get
|
# will override the requests.Response returned from requests.get
|
||||||
class MockResponse:
|
class MockResponse:
|
||||||
|
|
||||||
# mock json() method always returns a specific testing dictionary
|
# mock json() method always returns a specific testing dictionary
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def json():
|
def json():
|
||||||
|
@ -146,7 +146,6 @@ This can be done in our test file by defining a class to represent ``r``.
|
||||||
|
|
||||||
|
|
||||||
def test_get_json(monkeypatch):
|
def test_get_json(monkeypatch):
|
||||||
|
|
||||||
# Any arguments may be passed and mock_get() will always return our
|
# Any arguments may be passed and mock_get() will always return our
|
||||||
# mocked object, which only has the .json() method.
|
# mocked object, which only has the .json() method.
|
||||||
def mock_get(*args, **kwargs):
|
def mock_get(*args, **kwargs):
|
||||||
|
@ -181,6 +180,7 @@ This mock can be shared across tests using a ``fixture``:
|
||||||
# app.py that includes the get_json() function
|
# app.py that includes the get_json() function
|
||||||
import app
|
import app
|
||||||
|
|
||||||
|
|
||||||
# custom class to be the mock return value of requests.get()
|
# custom class to be the mock return value of requests.get()
|
||||||
class MockResponse:
|
class MockResponse:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -358,7 +358,6 @@ For testing purposes we can patch the ``DEFAULT_CONFIG`` dictionary to specific
|
||||||
|
|
||||||
|
|
||||||
def test_connection(monkeypatch):
|
def test_connection(monkeypatch):
|
||||||
|
|
||||||
# Patch the values of DEFAULT_CONFIG to specific
|
# Patch the values of DEFAULT_CONFIG to specific
|
||||||
# testing values only for this test.
|
# testing values only for this test.
|
||||||
monkeypatch.setitem(app.DEFAULT_CONFIG, "user", "test_user")
|
monkeypatch.setitem(app.DEFAULT_CONFIG, "user", "test_user")
|
||||||
|
@ -383,7 +382,6 @@ You can use the :py:meth:`monkeypatch.delitem <MonkeyPatch.delitem>` to remove v
|
||||||
|
|
||||||
|
|
||||||
def test_missing_user(monkeypatch):
|
def test_missing_user(monkeypatch):
|
||||||
|
|
||||||
# patch the DEFAULT_CONFIG t be missing the 'user' key
|
# patch the DEFAULT_CONFIG t be missing the 'user' key
|
||||||
monkeypatch.delitem(app.DEFAULT_CONFIG, "user", raising=False)
|
monkeypatch.delitem(app.DEFAULT_CONFIG, "user", raising=False)
|
||||||
|
|
||||||
|
@ -404,6 +402,7 @@ separate fixtures for each potential mock and reference them in the needed tests
|
||||||
# app.py with the connection string function
|
# app.py with the connection string function
|
||||||
import app
|
import app
|
||||||
|
|
||||||
|
|
||||||
# all of the mocks are moved into separated fixtures
|
# all of the mocks are moved into separated fixtures
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_test_user(monkeypatch):
|
def mock_test_user(monkeypatch):
|
||||||
|
@ -425,7 +424,6 @@ separate fixtures for each potential mock and reference them in the needed tests
|
||||||
|
|
||||||
# tests reference only the fixture mocks that are needed
|
# tests reference only the fixture mocks that are needed
|
||||||
def test_connection(mock_test_user, mock_test_database):
|
def test_connection(mock_test_user, mock_test_database):
|
||||||
|
|
||||||
expected = "User Id=test_user; Location=test_db;"
|
expected = "User Id=test_user; Location=test_db;"
|
||||||
|
|
||||||
result = app.create_connection_string()
|
result = app.create_connection_string()
|
||||||
|
@ -433,7 +431,6 @@ separate fixtures for each potential mock and reference them in the needed tests
|
||||||
|
|
||||||
|
|
||||||
def test_missing_user(mock_missing_default_user):
|
def test_missing_user(mock_missing_default_user):
|
||||||
|
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_ = app.create_connection_string()
|
_ = app.create_connection_string()
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,7 @@ and use pytest_addoption as follows:
|
||||||
|
|
||||||
# contents of hooks.py
|
# contents of hooks.py
|
||||||
|
|
||||||
|
|
||||||
# Use firstresult=True because we only want one plugin to define this
|
# Use firstresult=True because we only want one plugin to define this
|
||||||
# default value
|
# default value
|
||||||
@hookspec(firstresult=True)
|
@hookspec(firstresult=True)
|
||||||
|
|
Loading…
Reference in New Issue