-
Notifications
You must be signed in to change notification settings - Fork 2
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
Francescalb/testing dependencies #142
Francescalb/testing dependencies #142
Conversation
Removed hard requirement on DLite in tests.
This allows for testing locally and then pytest does not check global imports
Only test backends that are installed in triplestore
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #142 +/- ##
==========================================
- Coverage 75.67% 75.08% -0.59%
==========================================
Files 17 17
Lines 1402 1405 +3
==========================================
- Hits 1061 1055 -6
- Misses 341 350 +9
☔ View full report in Codecov by Sentry. |
Sparqlwrapper test skipped if package missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we want to tie ourselves to pytest this is a great PR that does what it intends to do and nothing more. Approves under that premises.
The bad thing is that the tests becomes less readable (or at least it require that the reader spends time that could have been used for something else to learn pytest) and makes interactive debugging with e.g. ipython impossible (because the pytest --pdb option is broken).
Another possibility would be to find an alternative test runner that doesn't load the tests without properly importing them and fails for missing packages even for test scripts that exit gracefully if depending packages are not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only "hard" change I'd request is the usage of v4 for the actions/checkout
GitHub action in ci_tests.yml
. As well as possibly adding version specifiers for pytest
and pytest-cov
in the same file.
Excellent work here 👍
.github/workflows/ci_tests.yml
Outdated
pip install pytest | ||
pip install pytest-cov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure stability it would be nice to constrict these installations to a version range. This can be most easily done in three different ways, two of which ensures dependabot updates, and again one of those that would require no changes to the dependabot config:
- Add version specifiers directly in this line (probably copying those already existing in
pyproject.toml
.
Requires_: Manually checking and updating the version specifiers later. - Create new
requirements_testing_basic.txt
or similar in.github/utils/
or similar directory within the.github
directory. This file then includes thepytest
andpytest-cov
dependencies including version specifiers as given currently inpyproject.toml
. This file is then installed here like:pip install -r .github/utils/requirements_testing_basic.txt
, instead of these lines.
Requires: Updating the dependabot config file (at.github/dependabot.yml
) to include automatic updates of the requirements file. See below this list what this addition should look like. - Add a new extra in
pyproject.toml
called "testing-core" or "testing-framework" or similar that only includespytest
andpytest-cov
with the version specifiers already existing in thepyproject.toml
under the "testing" extra. This extra is then installed here like:pip install -e .[testing-core]
, removing thepip install -e .
line as well as these two line.
Requires: No extra work, only the change inpyproject.toml
. The specifiers will be automatically checked and updated.
Here follows the addition to dependabot.yml
if choice number 2 from the above list is chosen:
- package-ecosystem: pip
directory: "/.github/utils"
schedule:
interval: weekly
day: monday
time: "05:18"
# Should be bigger than or equal to the total number of dependencies (currently 2)
open-pull-requests-limit: 5
target-branch: ci/dependency-updates
labels:
- CI/CD
- skip_changelog
Note: If the requirements file is not put in .github/utils/
the value for directory
above should be changed accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer option 3
tests/convert/test_convert.py
Outdated
|
||
def test_convertions(): | ||
"""Test convertions. Uses rdflib as triplestore backend""" | ||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pytest can be imported at the top-level, i.e., outside the functions at the top of the file, if so desired?
Then you can put the pytest.importorskip("rdflib")
at the top of the file out side the function as well.
In this way the test will truly just contain what it's about: the test.
By putting it outside it will also ensure that these lines will not have to be repeated if new test functions should be created in this file that requires rdflib
- however, if the file will contain a mix of tests that require and not require rdflib
, then this approach is to be preferred.
Note, a kind reminder that all comments here are in general suggested changes, this in particular is indeed only a suggestion.
This comment holds for all other places in this PR that a similar thing is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thought about it. I really prefer to do the importorskip for each test-function. To make sure that one does not accidentally skip new function added at a later stage. It is easy to miss out on things at the top of the file.
pytest can of course be moved outside.
from __future__ import annotations # Support Python 3.7 (PEP 585) | ||
|
||
import subprocess # nosec: B404 | ||
from collections import defaultdict | ||
from enum import Enum | ||
from typing import TYPE_CHECKING, Mapping, Sequence | ||
|
||
import numpy as np | ||
from pint import Quantity # remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not part of this PR, so this comment can be disregarded (or a follow-up issue opened).
Why is there a # remove
comment for this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know. I'd leave it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made issue
Co-authored-by: Casper Welzel Andersen <[email protected]>
Co-authored-by: Casper Welzel Andersen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Casper Welzel Andersen <[email protected]>
Description:
Type of change:
Checklist for the reviewer:
This checklist should be used as a help for the reviewer.