flake8-pytest-style icon indicating copy to clipboard operation
flake8-pytest-style copied to clipboard

Rule to support deprecations: tmpdir->tmp_path && tmpdir_factory->tmp_path_factory

Open webknjaz opened this issue 5 years ago • 2 comments
trafficstars

Rule request

Description

Basically, whenever a deprecated fixture is encountered, the linter should warn about this and suggest a better replacement as per $sbj.

Rationale

The pytest fixtures list suggests that there's better alternatives for tmpdir and tmpdir_factory that return old-style shims:

tmp_path Provide a pathlib.Path object to a temporary directory which is unique to each test function. tmp_path_factory Make session-scoped temporary directories and return pathlib.Path objects. tmpdir Provide a py.path.local object to a temporary directory which is unique to each test function; replaced by tmp_path. tmpdir_factory Make session-scoped temporary directories and return py.path.local objects; replaced by tmp_path_factory.

I saw this in a few other places in the docs but it's not emphasized enough. I often don't remember which one to use and add tmpdir expecting pathlib(2).Path objects there when I should use tmp_path instead to achieve this. Every time I have to go to docs to find out which one is old. It's PITA and a new rule could be very helpful here, plus it could be a framework for any future deprecations that may happen later.

webknjaz avatar Apr 22 '20 16:04 webknjaz

Another example of a deprecated fixture is mock -> mocker from pytest-mock.

m-burst avatar Apr 22 '20 18:04 m-burst

Right. Also: monkeypatch, especially where mock objects are not used, but it's harder to detect. Or where env vars, cwd, attrs are patched.

webknjaz avatar Apr 22 '20 18:04 webknjaz