astropy: Pytest: "found no collectors", cannot test my changes

When following the astropy contributing and testing guidelines: here

I get this error after running pytest in the root astropy repo. The error only occurs if I have made any changes to astropy, but tests all pass otherwise.

Any advice would be greatly appreciated.

============================= test session starts ==============================
platform darwin -- Python 3.13.2, pytest-8.3.5, pluggy-1.5.0

Running tests with Astropy version 7.1.dev876+ge06963e7b0.d20250427.
Running tests in astropy docs.

Date: 2025-04-27T13:15:35

Platform: macOS-10.16-x86_64-i386-64bit-Mach-O

Executable: /Users/rithwik/opt/anaconda3/envs/astropy-dev/bin/python

Full Python Version: 
3.13.2 | packaged by Anaconda, Inc. | (main, Feb  6 2025, 12:54:57) [Clang 14.0.6 ]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions: 
Numpy: 2.2.5
Scipy: 1.15.2
Matplotlib: 3.10.1
h5py: 3.13.0
Pandas: 2.2.3
PyERFA: 2.0.1.5
Cython: not available
Scikit-image: not available
asdf-astropy: 0.7.1
pyarrow: 19.0.1

Using Astropy options: remote_data: none.

CI: undefined
ARCH_ON_CI: undefined
IS_CRON: undefined

rootdir: /Users/rithwik/Desktop/astropy
configfile: pyproject.toml
testpaths: astropy, docs
plugins: astropy-0.11.0, remotedata-0.4.1, filter-subpackage-0.2.0, doctestplus-1.4.0, astropy-header-0.2.2, hypothesis-6.131.9, arraydiff-0.6.1, asdf-4.1.0, mock-3.14.0, cov-6.1.1, xdist-3.6.1
collected 0 items / 1 error                                                    

==================================== ERRORS ====================================
______________________________ ERROR collecting . ______________________________
../../opt/anaconda3/envs/astropy-dev/lib/python3.13/site-packages/pluggy/_hooks.py:513: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
../../opt/anaconda3/envs/astropy-dev/lib/python3.13/site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../../opt/anaconda3/envs/astropy-dev/lib/python3.13/site-packages/_hypothesis_pytestplugin.py:458: in pytest_ignore_collect
    warnings.warn(
E   UserWarning: Skipping collection of '.hypothesis' directory - this usually means you've explicitly set the `norecursedirs` pytest config option, replacing rather than extending the default ignores.
=========================== short test summary info ============================
ERROR . - UserWarning: Skipping collection of '.hypothesis' directory - this usually ...
=============================== 1 error in 0.64s ===============================
ERROR: found no collectors for /Users/rithwik/Desktop/astropy/astropy

ERROR: found no collectors for /Users/rithwik/Desktop/astropy/docs```

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

The diagnosis @braingram posted is correct, although it is useful to remark that the .hypothesis/ directory does not have to be created by hypothesis. An empty .hypothesis/ directory is sufficient to reproduce the reported bug.

It is not obvious to me why pytest tries to look into .hypothesis/ at all, given that we do make use of the testpaths setting: https://github.com/astropy/astropy/blob/fec4793d1d5935d04b88f5e62d3e258e6b3079ec/pyproject.toml#L204-L207 But I see no harm in having pytest ignore any hidden directories and it does solve the problem.

I think this is due to “.hypothesis” being searched by pytest which hypothesis generates a warning for: https://github.com/HypothesisWorks/hypothesis/pull/4212 which astropy then turns into an error. This only occurs for me on the 2nd run of pytest (the first is needed to create the “.hypothesis” directory).

Would you try adding ".*" to “pyproject.toml” under the pytest norecursedirs section: https://github.com/astropy/astropy/blob/fec4793d1d5935d04b88f5e62d3e258e6b3079ec/pyproject.toml#L208C1-L210

pytest mentions that defining norecursedirs will override the defaults (which includes “.*”) which is leading to the error (and slowing down test collection).

I too have found thatpytest --pyargs astropy works, but no other commands work, they give the same aforementioned error.

Specifically, I would like to run:

pytest astropy/io/fits/hdu/compressed or just pytest --pyargs astropy/io

but these don’t work.