Fix local (Windows) tests#1302
Merged
Merged
Conversation
Note: Colocation of the results and cache store w was causing issues with Window's file share locking.
Note reading the ORC format with pyarrow (through pandas) requires the IANA timezone database to be installed (`tzdata`) and thc `TZDIR` environment variables to be set.
Note: Plotly uses `kaleido` on windows to generate static images which has known issues. See plotly/Kaleido#110 or plotly/Kaleido#41 for more info.
Contributor
There was a problem hiding this comment.
❌ Changes requested. Reviewed everything up to 6a9e7c1 in 1 minute and 23 seconds
More details
- Looked at
108lines of code in6files - Skipped
0files when reviewing. - Skipped posting
14drafted comments based on config settings.
1. hamilton/io/utils.py:37
- Draft comment:
Review the condition for Windows drive paths. Relying on parsed.scheme.isalpha() might catch non-local schemes (e.g., 'http') if os.path.exists returns false, but it could be clearer by explicitly checking for a single-letter drive (e.g., len(scheme)==1). - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
The current code uses isalpha() which would match any alphabetic string, while Windows drive letters are always single characters. The comment's suggestion to use len(scheme)==1 is more precise for Windows drives. However, the code already has os.path.exists() as a second condition, which would prevent false positives from other schemes. The change would be marginally more precise but doesn't fix a real problem.
The current code already works correctly due to the os.path.exists check, and the suggested change doesn't fix any actual issues. The comment might be making the code more complex without adding value.
While the suggestion is technically more precise, the current implementation is already safe and functional. The added complexity isn't justified by any real-world benefit.
The comment should be deleted as it suggests a change that doesn't fix any actual problems and could make the code unnecessarily more complex.
2. tests/caching/metadata_store/test_base.py:48
- Draft comment:
The fixture now uses tmp_path_factory.mktemp('result_store'). Verify that the folder name is appropriate for metadata_store; using 'result_store' might be confusing. Consider renaming for clarity if needed. - Reason this comment was not posted:
Confidence changes required:50%<= threshold50%
None
3. tests/caching/result_store/test_base.py:19
- Draft comment:
The result_store fixture now uses tmp_path_factory for directory isolation. This change looks good for avoiding file lock issues on Windows. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
4. tests/plugins/test_pandas_extensions.py:244
- Draft comment:
Good use of mock.patch.dict to set the TZDIR environment variable. It might be helpful to add a comment documenting why this is required on Windows. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
5. tests/plugins/test_plotly_extensions.py:16
- Draft comment:
The skipif decorator for Windows in test_plotly_static_writer is appropriate given the issues with kaleido. Consider adding a short inline comment referencing the known dependency limitation. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
6. tests/test_telemetry.py:69
- Draft comment:
Using mock.patch.dict for TELEMETRY environment variable is a good practice. Documentation in Sphinx under telemetry configuration should note this approach for isolating environment settings during tests. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
7. tests/caching/metadata_store/test_base.py:49
- Draft comment:
Consider using a more descriptive and unique temporary directory name for the metadata_store fixture (e.g., 'metadata_store' instead of 'result_store') to avoid potential collisions with other fixtures. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50%
The temporary directory name is only used for tests and doesn't affect functionality. While matching names might be slightly clearer, this is a very minor stylistic suggestion. The current name 'result_store' is not incorrect or misleading - the metadata store does store results. The comment about "avoiding collisions" seems speculative since pytest handles temp directory isolation.
The suggestion could improve code readability by maintaining consistent naming. The collision concern might be valid if multiple tests run in parallel.
The naming improvement is too minor to warrant a comment, and tmp_path_factory already handles directory isolation, so collisions aren't a real concern.
This comment should be deleted as it suggests a minor stylistic change that doesn't meaningfully improve the code.
8. tests/plugins/test_pandas_extensions.py:244
- Draft comment:
Good use of mock.patch.dict to set the TZDIR environment variable for Windows compatibility. Consider adding a note in the Sphinx documentation (e.g., under a platform-specific testing section) about this workaround. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
9. tests/plugins/test_plotly_extensions.py:16
- Draft comment:
Using pytest.mark.skipif to skip the static image export test on Windows is a good practice. Consider documenting the known limitation regarding Plotly's Kaleido on Windows in the test documentation for future maintainers. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
10. tests/test_telemetry.py:69
- Draft comment:
Mocking the HAMILTON_TELEMETRY_ENABLED environment variable with @mock.patch.dict improves test isolation compared to direct os.environ changes. This pattern is effective for ensuring consistent telemetry behavior in tests. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
11. hamilton/io/utils.py:19
- Draft comment:
Typographical error: The phrase 'come chat so that we can make sure we don't break your code' is used in the docstring (line 19) of get_file_metadata. Consider rephrasing it (e.g., 'please contact us' or 'reach out to us') for clarity. This issue also appears in other docstrings and should be corrected consistently. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
12. tests/caching/result_store/test_base.py:14
- Draft comment:
Typo in the error message: the error string references_instantiate_metadata_store(), but should correctly reference_instantiate_result_store()to match the function name. Please update this to avoid confusion. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
13. tests/plugins/test_pandas_extensions.py:197
- Draft comment:
Typo alert: In the test_pandas_feather_writer function, the assertion is usingPandasStataWriter.applicable_types()instead ofPandasFeatherWriter.applicable_types(). Also, the file path uses the extension '.dta', which is typically for Stata files. Please update these to reference the Feather writer and use an appropriate file extension (e.g., '.feather'). - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
14. tests/plugins/test_pandas_extensions.py:153
- Draft comment:
Typo/consistency note: In the test_pandas_html_writer function, the output file is named 'test.xml'. Since this test is for an HTML writer, consider renaming the file to use an '.html' extension for clarity and consistency. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_qSWPBSAukA6rKurJ
Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.
elijahbenizzy
approved these changes
Apr 7, 2025
elijahbenizzy
left a comment
Contributor
There was a problem hiding this comment.
This looks good, and all tests pass. Unfortunately we don't hav ea windows github action VM, although I'd be surprised if it was hard. But I think this "does no harm" and likely makes dev easier. Shipping!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have been encountering errors and/or failures when running the test suite, locally, on a Windows machine. This pull request includes several changes aimed at allowing the test suite to pass. All changes, expect the first one, are confined to the offending tests.
Changes
File Handling Improvements:
hamilton/io/utils.py: Enhanced theget_file_metadatafunction to correctly handle Windows drive paths where theschemefromparse.urlparsemay include the Windows drive letter.Testing Fixture Updates:
tests/caching: Because themetadata_storeandresult_storeused the same temporary directory, deletions during clean-up were running into Window's file share locking. Switched to thetmp_path_factoryfixture and decoupled the paths for themetadata_storeandresult_storeEnvironment Variable Mocking:
tests/plugins/test_pandas_extensions.py: Added mocking for theTZDIRenvironment variable in thetest_pandas_orc_readertest. Note this is due to how Windows interacts with the IANA timezone database.tests/test_telemetry.py: Added mocking for theHAMILTON_TELEMETRY_ENABLEDenvironment variable in telemetry configuration tests. Previous tests were changingos.environdirectly leading to issues if the user already had ``HAMILTON_TELEMETRY_ENABLED` set.Platform-Specific Test Adjustments:
tests/plugins/test_plotly_extensions.py: Added a platform check to skip thetest_plotly_static_writertest on Windows. There are some issue with using theplotlydependencykaleidoto generate static images on Windows.How I tested this
N/A
Notes
N/A
Checklist