Skip to content

fix: Skip tests when running without dependencies from the root (griffe) - #485

Merged
pawamoy merged 5 commits into
mkdocstrings:mainfrom
Jazzcort:fix-test-in-griffelib
Aug 22, 2026
Merged

fix: Skip tests when running without dependencies from the root (griffe)#485
pawamoy merged 5 commits into
mkdocstrings:mainfrom
Jazzcort:fix-test-in-griffelib

Conversation

@Jazzcort

Copy link
Copy Markdown
Contributor

For reviewers

  • I did not use AI
  • I used AI and thoroughly reviewed every code/docs change

Description of the change

When running tests within griffelib alone as root, importing griffecli and mkdocstrings at module level causes ModuleNotFoundError. Defer these imports and guard them with pytest.importorskip() so the tests skip gracefully instead of failing.

Introducing those two dependencies to griffelib to just being able to run these tests does not seem like a reasonable choice. Therefore, the best solution I can think of is to gracefully bypass those tests.

I can also bypass those tests by manually skip them while running pytest but I feel like the tests come with the package should be error-free.

Relevant resources

When running tests within `griffelib` alone as root, importing `griffecli`
and `mkdocstrings` at module level causes `ModuleNotFoundError`. Defer
these imports and guard them with `pytest.importorskip()` so the tests
skip gracefully instead of failing.
@Jazzcort
Jazzcort force-pushed the fix-test-in-griffelib branch from 3174f6b to 888f85a Compare August 20, 2026 20:40
@Jazzcort
Jazzcort marked this pull request as draft August 20, 2026 20:44
@Jazzcort

Copy link
Copy Markdown
Contributor Author

more errors showing up. let me look into it.

@pawamoy

pawamoy commented Aug 21, 2026

Copy link
Copy Markdown
Member

Thanks! Looks like the test errors are unrelated to your changes (too old actions?). Let me try to fix them.

@pawamoy

pawamoy commented Aug 21, 2026

Copy link
Copy Markdown
Member

LGTM! Feel free to move out of draft when you're ready, and I'll squash-merge 🙂 Thanks!

@Jazzcort
Jazzcort force-pushed the fix-test-in-griffelib branch from 8526b24 to a11d24c Compare August 21, 2026 20:39
@Jazzcort

Copy link
Copy Markdown
Contributor Author

Hit a few more errors while running test with griffelib as the root. I think griffe-inherited-docstrings should not be tested in the griffelib test because it actually depends on griffelib. I guess this is the artifact that needs to be cleaned up after splitting tests into griffelib and griffecli. 🤔

I also added the optional test dependencies for griffelib which makes running test within griffelib more intuitive. 😁 It's very helpful while running the tests during packaging process.

Thank you so much for reviewing and working on this with me! Let me know if you like the changes or not. 😁

@Jazzcort
Jazzcort marked this pull request as ready for review August 21, 2026 20:56
Comment thread packages/griffelib/pyproject.toml Outdated
# The 'pypi' extra provides dependencies needed for the load_pypi functionality
# to download and inspect packages from PyPI.
pypi = ["pip>=24.0", "platformdirs>=4.2", "wheel>=0.42"]
test = ["pytest>=8.2", "pytest-gitconfig>=0.8.0", "jsonschema>=4.18"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set these as dev-dependencies instead? I'm not yet sold on declaring development dependencies as extras.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually leaning more toward your idea - put the test deps in the dev-dependencies. It's just because I saw so many packages is using %pyproject_buildrequires -x test, but the newer "%pyproject_buildrequires -g test" does exist so there shouldn't be any blocker for making them as dev-dependencies. 😁 I'll go ahead and move these dependencies to dev-deps.

@pawamoy

pawamoy commented Aug 21, 2026

Copy link
Copy Markdown
Member

Thanks!

I guess this is the artifact that needs to be cleaned up after splitting tests into griffelib and griffecli. 🤔

Do you mean there's room for improving the setup here, rather than just excluding the extension?

Thank you so much for reviewing and working on this with me!

It's only fair! Thanks for packaging the project for Fedora!

@Jazzcort
Jazzcort force-pushed the fix-test-in-griffelib branch from a11d24c to 3c1826f Compare August 21, 2026 22:21
@Jazzcort

Copy link
Copy Markdown
Contributor Author

Do you mean there's room for improving the setup here, rather than just excluding the extension?

TBH, I think you know more about the module import in python than me. I don't really think I can give you any constructive advices. It's just from my point of view I think griffe-inherited-docstrings is extending griffelib since it depends on it. griffelib shouldn't be testing the functionality of griffe-inherited-docstrings. Also, since griffe-inherited-docstrings has its own release cycle which may introduce breaking changes. If those breaking changes cause the test to fail in griffelib, it's not right in my opinion.

Anyway, it should be good to go. Thanks again! 😁

@pawamoy

pawamoy commented Aug 22, 2026

Copy link
Copy Markdown
Member

We depend on griffe-inherited-docstrings for the documentation of the public API. If we don't load it in our public API tests, I think it doesn't matter because the impacted tests aren't run since I suppose there's no objects.inv in your packaging/testing environment. It's an official extension, we have control over it, so breaking changes are not something to worry about too much 🙂 OK, merging!

@pawamoy
pawamoy merged commit e69dcc8 into mkdocstrings:main Aug 22, 2026
34 checks passed
@pawamoy

pawamoy commented Aug 22, 2026

Copy link
Copy Markdown
Member

Woops, should have been a test type, I'll amend and force-push on main.

pawamoy added a commit that referenced this pull request Aug 22, 2026
…iffe)

When running tests within `griffelib` alone as root, importing `griffecli` and `mkdocstrings` at module level causes `ModuleNotFoundError`. Defer these imports and guard them with `pytest.importorskip()` so the tests skip gracefully instead of failing.

Issue-484: #484
PR-485: #485
Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
@Jazzcort

Copy link
Copy Markdown
Contributor Author

We depend on griffe-inherited-docstrings for the documentation of the public API.

I see.

I think it doesn't matter because the impacted tests aren't run since I suppose there's no objects.inv in your packaging/testing environment.

Yes, you're right. There is no objects.inv in the packaging environment. 😁

Thanks! It's a pleasure to work with you! 😁

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