-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I use a patch wrapper in test, PTO19 fires when the patched items passed into the argument are unused #202
Comments
Hi @jplhanna, I am not sure when I can find the time to look into a proper fix. @pytest.fixture()
def _mock_get_config(mocker):
mocker.patch.object(Config, "get_first", return_value=None)
@pytest.fixture()
def _mock_db(mocker):
mocker.patch("src.app.config.controllers.db")
@pytest.mark.usefixtures("_mock_get_config", "_mock_db")
class TestCreateConfigFromExisting:
def test_new_config_has_given_unit(self):
# Arrange
mock_unit = MagicMock()
existing_config = Config(categories=[])
# Act
config = create_item_from_existing(mock_unit, existing_config)
# Assert
assert config.unit == mock_unit |
Thanks for the suggestion! It might be tough to use for the current project but I'll keep it in mind for future ones. |
when the name |
I would suggest using |
Bug report
What's wrong
I use the unit test patch as a wrapper around test cases and test functions, which requires the patched items to be passed into the test as the first X arguments.
The name of the arguments doesn't matter, they are just passed in reverse order of the patches.
When running flake8 against a test file with such a use case and the argument is not used, PT019 will fire saying the fixture without value should be placed in
pytest.mark.usefixtures
.Example:
_mock_db
and_get_config
will fire PT019How it should work
I would expect this case to be ignored, or suggest placing
_
in front of the argument if the patched item is not used in the test.System information
The text was updated successfully, but these errors were encountered: