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

Pytest: unittest => pytest Conversion #1742

Merged
merged 7 commits into from
Feb 1, 2025

Conversation

b8zhong
Copy link
Contributor

@b8zhong b8zhong commented Jan 31, 2025

Summary

Previous tests were in unittest, and should now be inline with pytest (resolves #1686)

Previous tests in signal_type were converted to pytest

Formatted with black hasher-matcher-actioner python-threatexchange.

Test Plan

Added tests.

Previous tests in `signal_type` were converted to pytest
Copy link
Contributor

@Dcallies Dcallies left a comment

Choose a reason for hiding this comment

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

Thanks a ton @b8zhong for the help! Your conversions look clean, and I appreciate the extra time you took to simplify or improve the tests!

Copy link
Contributor

@Dcallies Dcallies left a comment

Choose a reason for hiding this comment

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

Whoops, went too fast, there are some CI failures on some of the files you touched.

For the typing errors, use your best judgement on whether it's worth the time to fix typing in tests or whether to liberally sprinkle #type: ignore . I have soundtimes found typing catches unittest bugs, but more often than not it seems like too much effort.

@b8zhong
Copy link
Contributor Author

b8zhong commented Jan 31, 2025

@Dcallies Thanks for reviewing! Verified the test files now, passes with mypy tests --check-untyped-defs.

I thought typechecking would trigger whenever py files are touched though lol

@b8zhong
Copy link
Contributor Author

b8zhong commented Jan 31, 2025

Thanks for rerunning; put faiss as typeignore but I guess it doesn't like that whoops

Copy link
Contributor

@Dcallies Dcallies left a comment

Choose a reason for hiding this comment

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

It can be tricky to reproduce the exact results as CI - one trick I've done is check the version being installed by the CI, and I think we hardcode the version of mypy to help avoid random failures,

Settings say (from CI output at https://github.com/facebook/ThreatExchange/actions/runs/13074520123/job/36487583072?pr=1742):

platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0

mypy-1.7.1

Nothing jumps out to me from the CI failures - you might have some luck breaking the PR into one file at a time, but I'll leave that up to you.

@b8zhong
Copy link
Contributor Author

b8zhong commented Jan 31, 2025

@Dcallies Could you rerun now? Tried w/ pytest -W ignore::DeprecationWarning threatexchange/signal_type/tests -vv, all pass;

Passes (at least locally), so I think we should be good; caught a few things on my side. The test I marked as skip is because compare_hash isn't supported.. or I could just remove it. But let me know what you think

Copy link
Contributor

@Dcallies Dcallies left a comment

Choose a reason for hiding this comment

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

Looks like everything is passing now!

@Dcallies Dcallies merged commit c4dd84e into facebook:main Feb 1, 2025
6 checks passed
@b8zhong b8zhong deleted the pytest-conversion branch February 1, 2025 00:03
@b8zhong
Copy link
Contributor Author

b8zhong commented Feb 1, 2025

Thanks for merging David!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pytx][mlh] Convert some tests in threatexchange/signal_type/ to py.test
3 participants