Tox does not find the requirements file

Viewed 348

I have a Python module in which the setup.py script starts as follows:

import setuptools, pathlib

HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
REQUIRES = (HERE / "requirements.txt").read_text().strip().split("\n")

setuptools.setup(
   install_requires=REQUIRES,
   long_description=README,
   ...
)

When I run the setup from the command line, like this:

python setup.py sdist

it runs fine. But when I run

tox

I get an error on line 5 in file setup.py:

FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

even though both the requirements.txt file and the README.md file remain in the same folder as setup.py.

Here is my tox.ini file:

[tox]
envlist = py39

[testenv]
deps =
    pytest
    -r requirements.txt
commands =
    pytest

How can I make tox find my requirements.txt file?

2 Answers

As a complementary answer to the correct one by Erel.

Depending on configuration, tox builds the project, installs the build artifact and then tests against it. This is a good thing as only then you test what you ship, and not what is in the source tree.

In order to not forget to include files in the MANIFEST.in file, I usually use the check-manifest tool/linter, see https://pypi.org/project/check-manifest/

Two minor notes

I found the answer myself. The problem was that requirements.txt was not included by my 'MANIFEST.in' file. I changet the file to:

include pyproject.toml
include *.md
include *.txt
include LICENSE

and now tox works.

Related