STY: Prefer using pytest temporary path fixtures in tests - #126
Conversation
7c9fa9b to
87b3a41
Compare
|
This requires some more thinking. The memmap test file was doing trx-python/trx/tests/test_memmap.py Line 26 in 96876f4 But then all test functions requiring a temporary directory were using the same variable name in the context: trx-python/trx/tests/test_memmap.py Line 354 in 96876f4 So I do not believe the design was that correct, and this PR is probably uncovering that. |
79f3fae to
1fe0c5c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #126 +/- ##
==========================================
- Coverage 86.53% 86.49% -0.05%
==========================================
Files 13 13
Lines 2896 2887 -9
==========================================
- Hits 2506 2497 -9
Misses 390 390
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1fe0c5c to
98aa419
Compare
Prefer using the `pytest` `tmp_path` fixture in tests over the standard library `tempfile.TemporaryDirectory()`: - Makes the code more readable as no additional context (and the associated indentation) required by the use of `TemporaryDirectory` is needed. - Simplifies path manipulation as they return a `pathlib.Path` object and thus, no recurrent casting to `Path` is necessary. - Increases consistency in temporary directory naming, and thus, eases maintenance. - Fixes ``` Shadows name 'tmp_dir' from outer scope ``` warnings across `test_memmap.py`. - Remove the unused/unnecessary `tmp_dir = get_trx_tmp_dir()` statement.
98aa419 to
f99628c
Compare
Refactor `trx_tmp_dir` test:
- Do not parametrize an argument named `tmp_path`: that name is reserved
for `pytest`'s built-in fixture, and reusing it as a string parameter
is misleading/shadowing-prone.
- Clarify test intent by separating concerns:
- Keep the existing integration-style coverage (through load path
behavior),
- add a direct unit test for `get_trx_tmp_dir()` so the env-variable
contract is verified explicitly.
The previous test did not clearly test `get_trx_tmp_dir` itself; it
inferred behavior indirectly via `tmm.load(...)`.
- Replace symbolic "~" handling with explicit env-driven expectations
(home path value, `use_working_dir`, and unset env -> system temp
dir), which makes the “home” case non-misleading and properly
asserted.
- Deduplicate branch-specific assertions by deriving a single expected
parent directory per parametrized case.
- Use `monkeypatch` for `TRX_TMPDIR` setup/teardown to guarantee env
isolation and automatic cleanup, preventing cross-test leakage and
order-dependent failures.
f99628c to
0296979
Compare
|
Re #126 (comment) No need for further action. Tests are passing. Pinging @arokem. |
|
LGTM |
Prefer using the
pytesttmp_pathfixture in tests:TemporaryDirectoryis needed.pathlib.Pathobject and thus, no recurrent casting toPathis necessary.Shadows name 'tmp_dir' from outer scopewarnings acrosstest_memmap.py.tmp_dir = get_trx_tmp_dir()statement.