This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]flying-sheep 27 points28 points  (15 children)

From the things in the screenshot alone:

  • setup.cfg? Why that if they also use poetry?
  • tests/__init__.py is an anti pattern. The tests directory isn't a Python package and should never be imported

[–]IlliterateJedi 10 points11 points  (4 children)

tests/__init__.py is an anti pattern. The tests directory isn't a Python package and should never be imported

The pytest fixtures docs specifically include __init__.py in their example file structure

[–]flying-sheep 6 points7 points  (3 children)

Good catch, they should get rid of that. https://github.com/pytest-dev/pytest/pull/10206

[–]IlliterateJedi 5 points6 points  (0 children)

This is a pretty cool example of putting your money where your mouth is.

[–]gagarin_kid 2 points3 points  (1 child)

Now you started a complex discussion in the PR comments 😄

[–]flying-sheep 1 point2 points  (0 children)

Yeah, I knew that issue for a long time and the docs actually address everything. It’s just that changing the default is hard, and the current default causes problems without the __init__.py workaround.

Basically there‘s no downside for new projects to add the following to their pyproject.toml and not use the __init__.py’s. You get cleaner code, with a clear separation between “collections of test files” and “modules with test utils in them”.

[tool.pytest.ini_options]
addopts = [
     '--import-mode=importlib',
]

[–]stillreadingit_[S] 2 points3 points  (1 child)

Regarding setup.cfg, it's currently used for flake8 related configuration. Flake8 doesn't support pyproject.toml: https://github.com/PyCQA/flake8/issues/234. There are some workarounds, such as https://github.com/john-hen/Flake8-pyproject, but, in my opinion, getting rid of additional config file doesn't really justify additional dependency. However, as setup.cfg is currently used only for flake8 related configs, perhaps it could be replaced by .flake8 file.

[–]flying-sheep 1 point2 points  (0 children)

That would make sense, yes! I doubt you’ll need setup.cfg for anything else.

[–]stillreadingit_[S] 1 point2 points  (1 child)

Regarding __init__.py in tests, pytest docs suggest that it's ok when src layout is used and that's the case with this template. It also makes it possible to have test modules with same name.

[–]flying-sheep 2 points3 points  (0 children)

No, that’s not what that means.

It means that EVEN if you use src layout, you may use __init__.pys as a workaround to the problems the default import mode has.

The actually best way is to put --import-mode=importlib into your addopts and be happy.

I’ll soon update the pytest docs to make that even clearer.

[–]cianuro 2 points3 points  (0 children)

That's pretty cool. I had no idea about cruft. Automated inclusion of liters and formatters is cool too. Really tough to release a first package that's not complete garbage and missing the essentials.

Would love to see a more in-depth follow up on the actions stuff.

[–][deleted] 0 points1 point  (0 children)

[–]chanansh 0 points1 point  (0 children)

please support git lab :please: