anishathalye / dotbot

A tool that bootstraps your dotfiles ⚡️
MIT License
7.04k stars 291 forks source link

Tests fail because the mocking strategy conflicts with pytest on Nixos #365

Open ludat opened 2 months ago

ludat commented 2 months ago

I'm trying to build this inside a nixos worker and it keeps failing, After inpecting the code and it looks like the problem appears because one of the assertions inside tests/conftest.py (of os.rename) conflicts with an internal usage inside pytest.

I'm not sure what's causing it but here's the log and building this on nixos mainline is failing now.

Here are the logs:

============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-8.2.2, pluggy-1.5.0
rootdir: /build/source
configfile: pyproject.toml
collected 97 items

tests/test_bin_dotbot.py ...                                             [  3%]
tests/test_clean.py ..........                                           [ 13%]
tests/test_cli.py ..........                                             [ 23%]
tests/test_config.py ....                                                [ 27%]
tests/test_create.py ....                                                [ 31%]
tests/test_link.py .................................ss............       [ 80%]
tests/test_noop.py ..                                                    [ 82%]
tests/test_shell.py ................                                     [ 98%]
tests/test_shim.py s                                                     [100%]
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/pytest/__main__.py", line 7, in <module>
    raise SystemExit(pytest.console_main())
                     ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/config/__init__.py", line 206, in console_main
    code = main()
           ^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/config/__init__.py", line 178, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/main.py", line 332, in pytest_cmdline_main
    return wrap_session(config, _main)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/main.py", line 320, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/logging.py", line 872, in pytest_sessionfinish
    return (yield)
            ^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/terminal.py", line 867, in pytest_sessionfinish
    result = yield
             ^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/warnings.py", line 140, in pytest_sessionfinish
    return (yield)
            ^^^^^
  File "/nix/store/jrc5vsl77kzmwn9d1lm5yrzgn5rg6s12-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 479, in pytest_sessionfinish
    config.cache.set("cache/nodeids", sorted(self.cached_nodeids))
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 187, in set
    self._mkdir(path.parent)
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 129, in _mkdir
    self._ensure_cache_dir_and_supporting_files()
  File "/nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/_pytest/cacheprovider.py", line 232, in _ensure_cache_dir_and_supporting_files
    path.rename(self._cachedir)
  File "/nix/store/z7xxy35k7620hs6fn6la5fg2lgklv72l-python3-3.12.4/lib/python3.12/pathlib.py", line 1363, in rename
    os.rename(self, target)
  File "/build/source/tests/conftest.py", line 50, in wrapper
    assert value == os.path.abspath(value), msg
AssertionError: The 'src' argument to os.rename() must be an absolute path
assert PosixPath('/build/source/pytest-cache-files-g3cjced1') == '/build/source/pytest-cache-files-g3cjced1'
 +  where '/build/source/pytest-cache-files-g3cjced1' = <function abspath at 0x7ffff72a5580>(PosixPath('/build/source/pytest-cache-files-g3cjced1'))
 +    where <function abspath at 0x7ffff72a5580> = <module 'posixpath' (frozen)>.abspath
 +      where <module 'posixpath' (frozen)> = os.path

NOTE: I don't really understand why this shows up in nixos but not on the CI

kurtmckee commented 1 week ago

You're running pytest, not tox to invoke the test suite.

Run tox to set up and execute the test suite environment in a supported way.

@anishathalye This ticket can be closed.