flake8-pytest-style
flake8-pytest-style copied to clipboard
Rule to support deprecations: tmpdir->tmp_path && tmpdir_factory->tmp_path_factory
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_pathProvide apathlib.Pathobject to a temporary directory which is unique to each test function.tmp_path_factoryMake session-scoped temporary directories and returnpathlib.Pathobjects.tmpdirProvide apy.path.localobject to a temporary directory which is unique to each test function; replaced bytmp_path.tmpdir_factoryMake session-scoped temporary directories and returnpy.path.localobjects; replaced bytmp_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.
Another example of a deprecated fixture is mock -> mocker from pytest-mock.
Right. Also: monkeypatch, especially where mock objects are not used, but it's harder to detect. Or where env vars, cwd, attrs are patched.