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

Fix running pytest in root of repo #208

Merged
merged 4 commits into from
Jul 12, 2023
Merged

Conversation

bgilbert
Copy link
Member

We can't test the openslide package in-repo because we need to use a copy that includes the compiled extension module. But even if the package was installed into the Python path, we couldn't run pytest in the root of the repo, because the openslide directory in the repo would take precedence.

Configure pytest not to modify the Python path, allowing it to properly use an installed openslide package. Also do some minor rearranging of tests.

Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
Minor cleanup.

Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
Treat tests as a directory full of modules, rather than as a package.
This will allow us to stop adding the root of the repo to the Python path.

Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
By default, running `pytest` prepends the source directory to the Python
path, since that's where the `tests` package is.  That causes Python to
import `openslide` from the source directory instead of using the
installed copy, and this fails because the source directory doesn't have
the compiled extension module.  Configure pytest not to change the Python
path, as recommended by pytest docs:

https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-an-import-mode

Then, manually set the Python path to allow tests to load common code.

Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
@github-actions
Copy link

DCO signed off ✔️

All commits have been signed off. You have certified to the terms of the Developer Certificate of Origin, version 1.1. In particular, you certify that this contribution has not been developed using information obtained under a non-disclosure agreement or other license terms that forbid you from contributing it under the GNU Lesser General Public License, version 2.1.

@bgilbert bgilbert merged commit 8878e59 into openslide:main Jul 12, 2023
@bgilbert bgilbert deleted the pytest branch July 12, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant