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

Minor test cleanup #1090

Merged
merged 3 commits into from
Oct 18, 2024
Merged

Minor test cleanup #1090

merged 3 commits into from
Oct 18, 2024

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Oct 18, 2024

  • Do not use parametrize with single value
  • Prefer scoped warning handlers (context manager + specific warning type)

📚 Documentation preview 📚: https://globus-sdk-python--1090.org.readthedocs.build/en/1090/

@sirosen sirosen added the no-news-is-good-news This change does not require a news file label Oct 18, 2024
Comment on lines 7 to 17
import globus_sdk
from globus_sdk import SearchQuery, SearchQueryV1, utils
from globus_sdk.exc.warnings import RemovedInV4Warning


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_init_legacy():
"""Creates SearchQuery and verifies results"""
query = SearchQuery()
with pytest.warns(
globus_sdk.exc.RemovedInV4Warning, match="'SearchQuery' is deprecated"
):
query = SearchQuery()
Copy link
Member

Choose a reason for hiding this comment

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

These imports, and the subsequent usage here, aren't looking okay to me.

globus_sdk doesn't need to be imported, and the RemovedInV4Warning doesn't need to be qualified.

    with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
        query = SearchQuery()

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, 🤦 , I missed that it was already imported by name.

That said, we document it as globus_sdk.RemovedInV4Warning, so I think it's best if the testsuite matches that usage. (Which is also not what I wrote!)

I'll make a change right now which is fairly minimal. Although I generally prefer the verbose style of importing a package name (in our case, globus_sdk) and accessing all of the qualified names we need from that name, rewriting the whole test module to use that style isn't the small change I had in mind for this PR.

In the module where a `from globus_sdk import ...` is used,
`RemovedInV4Warning` is imported there, inlining it with other imports
and matching the documented usage for users.

In the module where `import globus_sdk` is used, the warning is
accessed as `globus_sdk.RemovedInV4Warning`. Again, this matches
user-facing documentation.

The two modules are not made consistent *with one another*, but they
are now each internally consistent.

---

Separately, fix a small issue which crept in, in which multiple tests
were written in a single test function and I therefore failed to
attach the requisite context manager.
@sirosen sirosen merged commit 431afd9 into globus:main Oct 18, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-news-is-good-news This change does not require a news file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants