Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError if pytest is not installed #82

Closed
adamtheturtle opened this issue Sep 14, 2023 · 5 comments
Closed

ModuleNotFoundError if pytest is not installed #82

adamtheturtle opened this issue Sep 14, 2023 · 5 comments

Comments

@adamtheturtle
Copy link
Contributor

pytest is not defined as a requirement of sybil, but sybil depends on pytest.

  • Create a new Python environment
  • pip install sybil==5.0.3
  • Run the following code:
import sybil
sybil.Sybil(parsers=[]).pytest()

This raises the error:

ModuleNotFoundError: No module named '_pytest'

This is not caught by the tests because pytest is a test dependency.

I suggest that to fix this, move pytest to the install requirements for sybil.

FWIW a project like pip-check-reqs would find this issue.

@cjw296
Copy link
Member

cjw296 commented Sep 14, 2023

I think this is kindof expected? (ie: if you use the pytest integration without installing pytest you get an exception.
I don't want a hard dependency on pytest, and I don't really want to set up a pip install sybil[pytest] as I strongly suspect folks will already have pytest as a dep before they add Sybil.

@cjw296 cjw296 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2023
@adamtheturtle
Copy link
Contributor Author

Ok, the cost is that there is some complexity in #81.
The regular test suite did not catch the initial error there, it is only the docs builder that caught the issue there that showed that an import had to go in if TYPE_CHECKING - that seems like a risk, to me.

I think this is kindof expected?

Not by me, but that might come down to personal experience.

Some reasoning:

  • I never expect ModuleNotFoundError when using a library
  • By adding pytest as a requirement, Sybil can specify the versions of pytest it is compatible with. This allows pip users for example to get an error that they are installing Sybil with an incompatible version of pytest.
  • If I take a look at some popular libraries that I'm familiar with, which can reasonably expect another dependency to be installed, the ones I've looked at so far all have that other dependency explicitly stated in their requirements.
    • For example, I use sphinx-autodoc-typehints which one would only reasonably use with Sphinx, and it specifies Sphinx as a dependency
    • For example, I have used flake8-bugbear which one would only reasonably use with flake8, and it specifies flake8 as ad dependency.

@cjw296
Copy link
Member

cjw296 commented Sep 15, 2023

How can "pytest is a requirement if and only if you're using the pytest extension" be expressed in setup.py? I don't know the answer to that...

To be super clear: Sybil is currently usable without installing pytest and I have use cases where that matters, having a hard dependency on pytest breaks that, so it is not an acceptable solution.

@adamtheturtle
Copy link
Contributor Author

adamtheturtle commented Sep 16, 2023

How can "pytest is a requirement if and only if you're using the pytest extension" be expressed in setup.py? I don't know the answer to that...

I'm not sure what this means by "using the pytest extension", but I'm guessing that it is something that one wouldn't want to do (read source code in the installation process).

Another way that some projects may do this, if they want some functionality to depend on a library but they do not want to add that library as a dependency is to split the project in two. e.g. pip install sybil, and pip install sybil-pytest.

That said, these are all options with trade-offs which have some pros and cons in terms of simplicity, backwards compatibility, and the use cases where not having pytest matters.

@adamtheturtle
Copy link
Contributor Author

By adding pytest as a requirement, Sybil can specify the versions of pytest it is compatible with. This allows pip users for example to get an error that they are installing Sybil with an incompatible version of pytest.

This is now relevant as Sybil is broken with Pytest 8.0.0.

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

No branches or pull requests

2 participants