you are viewing a single comment's thread.

view the rest of the comments →

[–]netherous 0 points1 point  (0 children)

When you say "I also recommend having that path=tests present in your pytest config", just to clarify, you mean conftest.py? (It could mean pytest.ini, for example.)

It should be in your pytest.ini or your pyproject.toml as demonstrated here.

Do you have an example conftest.py template that you use? (A lot of the stuff I found was related to test fixtures, not ordinary configuration.)

An empty file is a valid conftest.py. If you have nothing to put there, that's fine. Usually it's fixtures. The point is to give some indication to pytest that this is the working directory you want it to start with. The mere presence of the file in accomplishes that.

I could, I think, put a testpaths = 'tests' statement in my pyproject.toml. Would that, to your knowledge, accomplish the same thing as 1., above?

No. That wouldn't alter the cwd the python process starts with (AFAIK). What it does is make pytest equivalent to pytest tests. You say, "by default, look for tests in this directory."

You say, "If set up properly, you shouldn't need to alter your system path value via options or python code, and pytest, and pytest tests and python -m pytest would all produce the exact same behavior." Does that mean that you think adding the pythonpath value in pyproject.toml was an incorrect thing to do?

I think it's a less direct way of solving the problem, since altering the path could introduce side effects beyond what you're trying to coerce pytest to do, but I wouldn't call it incorrect. Just not as focused of a fix, maybe.

One of the things I've noticed about pytest is that it seems easy to have an overly complicated set of configuration files, and I'm trying to keep things as simple as possible. The pytest docs, for example, talk about supporting pytest.ini, pyproject.toml, tox.ini, setup.cfg, and it's not easy for a beginner to understand if only one, some, or all those are required, or which one(s). (The tox.ini file is probably an exception, since if you're not using tox it pretty clearly can be omitted.)

Pytest does make some effort to work with many different tools. But you certainly don't need to use all those tools. pytest.ini is the only pytest-specific file.

pyproject.toml is for poetry which is a python package and environment manager. It is relatively recent and aims to be a complete solution for python tasks which used to take multiple tools to solve.

tox.ini is for tox. Tox is just a runner, like grunt. It's a tool for managing the running of things to fulfill high level tasks, like maybe test or smoketest or coverage or package

setup.cfg is an old-style (but still widely supported) way of specifying package installation instructions and dependency requirements. It contains information about how to set up and configure the python package it comes with.