Using python 3.6 (on a Mac Mojave; no virtualenv involved) I have the following setup: A folder containing the two folders
mymodule1
tests
The folder mymodule1
contains two files, an empty file __init__.py
and a file myfunctions.py
:
def func1(x):
return 2*x
and the folder test
contains one file test1.py
:
from mymodule1 import myfunctions
def test1():
assert myfunctions.func1(21) == 42
Since I want to run a py.test
within a tox environment, I also have the following two files in the main folder:
First the tox.ini
file (according to numerous examples):
[base]
name = mymodule1
[tox]
envlist =
py36
[testenv]
deps =
pytest
commands = py.test
which has the command py.test
and not python -m pytest
!!
Then the setup.py
file:
from setuptools import setup
setup(
name="mymodule1",
author="me",
description="Short description",
long_description="long description",
)
Running the command
py.test
on the command line gives the following error: ========================================================================================== test session starts =========================================================================================== platform darwin -- Python 3.6.9, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 rootdir: /Users/me/mymodule1 collected 0 items / 1 error
================================================================================================= ERRORS =================================================================================================
____________________________________________________________________________________ ERROR collecting tests/test1.py _____________________________________________________________________________________
ImportError while importing test module '/Users/me/mymodule1/tests/test1.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test1.py:1: in <module>
from mymodule1 import myfunctions
E ModuleNotFoundError: No module named 'mymodule1'
======================================================================================== short test summary info =========================================================================================
ERROR tests/test1.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================ 1 error in 0.17s ===========================================================================================
and running tox -e py36
gives the following output:
GLOB sdist-make: /Users/me/mymodule1/setup.py
py36 inst-nodeps: /Users/me/mymodule1/.tox/.tmp/package/1/mymodule1-0.0.0.zip
py36 installed: attrs==19.3.0,importlib-metadata==1.7.0,more-itertools==8.4.0,mymodule1 @ file:///Users/me/mymodule1/.tox/.tmp/package/1/mymodule1-0.0.0.zip,packaging==20.4,pluggy==0.13.1,py==1.9.0,pyparsing==2.4.7,pytest==5.4.3,six==1.15.0,wcwidth==0.2.5,zipp==3.1.0
py36 run-test-pre: PYTHONHASHSEED='3789759274'
py36 run-test: commands[0] | py.test
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 3.6.9, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
cachedir: .tox/py36/.pytest_cache
rootdir: /Users/me/mymodule1
collected 0 items / 1 error
================================================================================================= ERRORS =================================================================================================
____________________________________________________________________________________ ERROR collecting tests/test_1.py ____________________________________________________________________________________
ImportError while importing test module '/Users/me/mymodule1/tests/test_1.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_1.py:2: in <module>
from mymodule1 import myfunctions
E ModuleNotFoundError: No module named 'mymodule1'
======================================================================================== short test summary info =========================================================================================
ERROR tests/test_1.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================ 1 error in 0.15s ============================================================================================
ERROR: InvocationError for command /Users/me/mymodule1/.tox/py36/bin/py.test (exited with code 2)
________________________________________________________________________________________________ summary _________________________________________________________________________________________________
ERROR: py36: commands failed
What am I missing? How is it possible that other people can use a tox.ini
file invoking py.test
directly?
Additional information:
$ which python
/Users/me/.pyenv/shims/python
$ which py.test
/Users/me/.pyenv/shims/py.test