Pytest doesn't seem to recognize and run my tests

Viewed 128

So the previous answer to this question doesn't seem to work for me. But I think this problem has something to do with my package references or my setup.cfg file.

I have two tests (just to start with to try and get this working) the results are:

================================ test session starts ==================================================================================================================================================================

platform win32 -- Python 3.7.10, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- C:\Users\heasm\Anaconda3\envs\UofS\python.exe
cachedir: .pytest_cache
rootdir: C:\USask Python\geo_calcs, configfile: setup.cfg
collected 0 items

================================= warnings summary ====================================================================================================================================================================
..\..\Users\heasm\Anaconda3\envs\UofS\lib\site-packages\_pytest\config\__init__.py:1230
  C:\Users\heasm\Anaconda3\envs\UofS\lib\site-packages\_pytest\config\__init__.py:1230: PytestConfigWarning: Unknown config option: collect_ignore

    self._warn_or_fail_if_strict("Unknown config option: {}\n".format(key))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================ 1 warning in 0.61s ===================================================================================================================================================================

Now my setup.cfg file is:

current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:setup.py]
search = version='{current_version}'
replace = version='{new_version}'

[bumpversion:file:geo_calcs/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'

[bdist_wheel]
universal = 1

[flake8]
exclude = docs
[tool:pytest]
collect_ignore = ['setup.py']

My test cases all seem to be named correctly. Here is an example:

from geo_calcs.calculations.geochem import *

@pytest.fixture
def test_get_atomic_weight():
    assert get_atomic_weight(["Si","O","O"]) == 60.0843

Finally my directory structure is:

+---geo_calcs
|   |   .editorconfig
|   |   .gitignore
|   |   .travis.yml
|   |   AUTHORS.rst
|   |   CONTRIBUTING.rst
|   |   HISTORY.rst
|   |   LICENSE
|   |   Makefile
|   |   MANIFEST.in
|   |   README.rst
|   |   requirements_dev.txt
|   |   setup.cfg
|   |   setup.py
|   |   tox.ini
|   +---docs
|   |       authors.rst
|   |       conf.py
|   |       contributing.rst
|   |       history.rst
|   |       index.rst
|   |       installation.rst
|   |       make.bat
|   |       Makefile
|   |       readme.rst
|   |       usage.rst
|   |       
|   +---geo_calcs
|   |   |   utils.py
|   |   |   __init__.py
|   |   |   
|   |   +---calculations
|   |   |   |   geochem.py
|   |   |   |   geochron.py
|   |   |   |   __init__.py
|   |   |   |   
|   |   +---visualizations
|   |   |       __init__.py
|   |       
|   \---tests
|       |   test_utils.py
|       |   __init__.py
|       |   
|       +---calculations
|       |   |   test_geochem.py
|       |   |   test_geochron.py
|       |   |   __init__.py
|       |           
|       +---visualizations
|       |   |   __init__.py           

Does anyone have any insight?

1 Answers

Remove the @pytest.fixture decorator from above the test. Tests shouldn't have that, they're discovered by naming convention.

Pytest uses glob-style name patterns to collect tests, and the discovery can be customized by the options python_files, python_classes, and python_functions in the configuration file.

The default patterns are:

[pytest]
python_files=test_*.py
python_classes=Test*
python_functions=test_*
Related