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

Strip extra lines before and after the _WARNING_MSG #1117

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

frost-nzcr4
Copy link
Contributor

My proposal for fastapi_pagination/utils.py:_WARNING_MSG is to remove the extra lines from it. This makes it easier to filter warnings in pytest and other tools.

I've made a proof of concept for this PR https://github.com/frost-nzcr4/fastapi-pagination/tree/poc-pytest-filterwarning-not-matching-the-warning/docker.

You'll need to run:

git clone https://github.com/frost-nzcr4/fastapi-pagination.git
git checkout poc-pytest-filterwarning-not-matching-the-warning
cd docker
docker build . --tag fastapi-pagination-trim-extra-lines
docker run --rm fastapi-pagination-trim-extra-lines

and now you get ready for an error:

            if _check_installed(f"fastapi_pagination.ext.{ext}"):
>               warnings.warn(
                    _WARNING_MSG.format(ext=ext),
                    FastAPIPaginationWarning,
                    stacklevel=3,
                )
E               fastapi_pagination.utils.FastAPIPaginationWarning: 
E               Package "sqlalchemy" is installed.
E               
E               It's recommended to use extension "fastapi_pagination.ext.sqlalchemy" instead of default 'paginate' implementation.
E               
E               Otherwise, you can disable this warning by adding the following code to your code:
E               from fastapi_pagination.utils import disable_installed_extensions_check
E               
E               disable_installed_extensions_check()

/root/.cache/pypoetry/virtualenvs/fastapi-pagination-trim-extra-lines-_geWzZZ1-py3.11/lib/python3.11/site-packages/fastapi_pagination/utils.py:127: FastAPIPaginationWarning
=========================== short test summary info ============================
FAILED test_utils.py::test_warning - fastapi_pagination.utils.FastAPIPaginati...

The leading \n in _WARNING_MSG is non-obvious to filter with pytest filterwarnings and with -W.

@uriyyo uriyyo added the enhancement New feature or request label Apr 9, 2024
Copy link
Owner

@uriyyo uriyyo left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.11%. Comparing base (245519c) to head (e7bfe13).
Report is 160 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1117      +/-   ##
==========================================
+ Coverage   93.26%   94.11%   +0.84%     
==========================================
  Files          35       37       +2     
  Lines        1040     1275     +235     
==========================================
+ Hits          970     1200     +230     
- Misses         70       75       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@uriyyo uriyyo merged commit f7472e7 into uriyyo:main Apr 10, 2024
19 checks passed
@uriyyo
Copy link
Owner

uriyyo commented Apr 17, 2024

Hi @frost-nzcr4,

New version has been released that includes your fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants