Skip to content

Move tests to the toplevel#2057

Open
QuLogic wants to merge 1 commit into
fsspec:masterfrom
QuLogic:toplevel-tests
Open

Move tests to the toplevel#2057
QuLogic wants to merge 1 commit into
fsspec:masterfrom
QuLogic:toplevel-tests

Conversation

@QuLogic

@QuLogic QuLogic commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This is implementing #1611 (comment) and the main reason this has become relevant now is because Zarr 3 ships a pytest plugin. The pytest plugin is loaded early during setup and imports zarr, which imports fsspec from the installed copy before pytest even looks for tests. But tests are excluded from the installed copy (as configured in hatch.) So to run tests against an installed copy, we need to point pytest at the original source, but then it sees that those tests are in an fsspec module and gets confused:

==================================== ERRORS ====================================
___________________________ ERROR collecting fsspec ____________________________
/usr/lib/python3.15/site-packages/_pytest/config/__init__.py:731: in _importconftest
    mod = import_path(
/usr/lib/python3.15/site-packages/_pytest/pathlib.py:610: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('fsspec.conftest', '/builddir/build/BUILD/python-fsspec-2026.6.0-build/BUILDROOT/usr/lib/python3.15/site-packages/fsspec/conftest.py', PosixPath('/builddir/build/BUILD/python-fsspec-2026.6.0-build/filesystem_spec-2026.6.0/fsspec/conftest.py'))
=========================== short test summary info ============================
ERROR fsspec - _pytest.pathlib.ImportPathMismatchError: ('fsspec.conftest', '...

This works in current CI because all installs are editable, meaning the installed copy is the same as the source copy, and tests are always visible.

The main reason this has become relevant now is because Zarr 3 ships a
pytest plugin. The pytest plugin is loaded early during setup and
imports `zarr`, which imports `fsspec` from the _installed_ copy before
pytest even looks for tests. But tests are excluded from the installed
copy (as configured in hatch.) So to run tests against an installed
copy, we need to point pytest at the original source, but then it sees
that those tests are in an `fsspec` module and gets confused:
```
==================================== ERRORS ====================================
___________________________ ERROR collecting fsspec ____________________________
/usr/lib/python3.15/site-packages/_pytest/config/__init__.py:731: in _importconftest
    mod = import_path(
/usr/lib/python3.15/site-packages/_pytest/pathlib.py:610: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('fsspec.conftest',
        '/builddir/build/BUILD/python-fsspec-2026.6.0-build/BUILDROOT/usr/lib/python3.15/site-packages/fsspec/conftest.py',
	PosixPath('/builddir/build/BUILD/python-fsspec-2026.6.0-build/filesystem_spec-2026.6.0/fsspec/conftest.py'))
=========================== short test summary info ============================
ERROR fsspec - _pytest.pathlib.ImportPathMismatchError: ('fsspec.conftest', '...
```

This works in current CI because all installs are editable, meaning the
installed copy is the same as the source copy, and tests are always
visible.
@QuLogic

QuLogic commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

I am uncertain why CI/gcsfs-pytest is suddenly missing numpy; I don't believe I changed anything in regards to the CI setup.

@martindurant

Copy link
Copy Markdown
Member

Before going further here, is there no pytest flag on the other end that might fix this without any changes here? I understand that including the tests is no longer the done thing (since a long time), but it's still not a burden.

@QuLogic

QuLogic commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

I tried passing --import-mode=importlib to pytest, which should cause it to not try to add the current directory to the search path that could confuse with the installed copy.

Unfortunately, it got stuck at fsspec/implementations/tests/test_http.py::test_processes (with either zarr 2 or 3) If I skip that one, then I also get this failure:

__________________________________ test_mount __________________________________

mount_local = (local('/tmp/pytest-of-mockbuild/pytest-2/test_mount0/source'), local('/tmp/pytest-of-mockbuild/pytest-2/test_mount0/local'))

    def test_mount(mount_local):
        source_dir, mount_dir = mount_local
        assert os.listdir(mount_dir) == []
        assert os.listdir(source_dir) == []
    
        mount_dir.mkdir("a")
    
        assert os.listdir(mount_dir) == ["a"]
>       assert os.listdir(source_dir) == ["a"]
E       AssertionError: assert [] == ['a']
E         
E         Right contains one more item: 'a'
E         
E         Full diff:
E         + []
E         - [
E         -     'a',
E         - ]

fsspec/tests/test_fuse.py:114: AssertionError
---------------------------- Captured stderr setup -----------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.15/multiprocessing/forkserver.py", line 417, in main
    code = _serve_one(child_r, fds,
                      unused_fds,
                      old_handlers)
  File "/usr/lib64/python3.15/multiprocessing/forkserver.py", line 457, in _serve_one
    code = spawn._main(child_r, parent_sentinel)
  File "/usr/lib64/python3.15/multiprocessing/spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named 'fsspec.tests.test_fuse'. Did you mean: 'fsspec.tests.abstract'?

I think that import-mode=importlib + multiprocessing is just not supported at all: pytest-dev/pytest#10965

If you think that skipping these 2 tests is reasonably safe, then I could implement that downstream and not continue here.

@martindurant

Copy link
Copy Markdown
Member

If you think that skipping these 2 tests is reasonably safe

Sounds fine to me

No module named 'fsspec.tests.test_fuse'. Did you mean: 'fsspec.tests.abstract'?

Hah, not too close :)

@QuLogic

QuLogic commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Wait, I'm sorry, I accidentally tested with Zarr 2 twice. With Zarr 3, I get a bunch of this:

==================================== ERRORS ====================================
______ ERROR collecting fsspec/implementations/tests/test_asyn_wrapper.py ______
ImportError while importing test module '/builddir/build/BUILD/python-fsspec-2026.6.0-build/filesystem_spec-2026.6.0/fsspec/implementations/tests/test_asyn_wrapper.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
fsspec/implementations/tests/test_asyn_wrapper.py:12: in <module>
    from .test_local import csv_files, filetexts
fsspec/implementations/tests/test_local.py:20: in <module>
    from fsspec.tests.test_utils import WIN
E   ModuleNotFoundError: No module named 'fsspec.tests.test_utils'

The problem is that fsspec.tests doesn't exist in the installed copy and tests are split between there and fsspec/implementations/tests, and so it needs to use an absolute import path there. I will have to test whether switching to relative import paths will help or not.

@QuLogic

QuLogic commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Sadly relative imports are broken just the same:

______ ERROR collecting fsspec/implementations/tests/test_asyn_wrapper.py ______
ImportError while importing test module '/builddir/build/BUILD/python-fsspec-2026.6.0-build/filesystem_spec-2026.6.0/fsspec/implementations/tests/test_asyn_wrapper.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
fsspec/implementations/tests/test_asyn_wrapper.py:12: in <module>
    from .test_local import csv_files, filetexts
fsspec/implementations/tests/test_local.py:21: in <module>
    from ...tests.test_utils import WIN
E   ModuleNotFoundError: No module named 'fsspec.tests.test_utils'

I suppose I could try deleting the zarr pytest plugin; it doesn't seem super important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants