Skip to content

chore: use the fakeenv crate for testing environment variable specific functionality#50

Merged
haraldmaida merged 1 commit into
mainfrom
chore/use-fakeenv-for-testing-environment-variable-specific-functionality
Jun 8, 2025
Merged

chore: use the fakeenv crate for testing environment variable specific functionality#50
haraldmaida merged 1 commit into
mainfrom
chore/use-fakeenv-for-testing-environment-variable-specific-functionality

Conversation

@haraldmaida
Copy link
Copy Markdown
Member

Testing code that makes decisions based on the value of environment variables faces two problems:

  1. The tests can not run in parallel as setting or removing an environment variable in one testcase may influence other testcases
  2. As we know from Rust edition 2024 the functions std::env::set_var and std::env::remove_var are unsafe on some operating systems

For the first problem we used the serial_test crate to mark all tests that shall not run in parallel.

Using a fake "environment", that mimics the related functions from the std::env module, for testing solves both problems. The crate serial_test is no longer needed as a dependency.

Refactored tests in colored::tests module to use a fake environment and removed the serial_test dependency.

…fic functionality - crate `serial_test` is no longer needed
@haraldmaida haraldmaida self-assigned this Jun 8, 2025
@haraldmaida haraldmaida added the development An internal change related to development of this codebase label Jun 8, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.70%. Comparing base (29f1efa) to head (9b3e223).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage   96.69%   96.70%           
=======================================
  Files          30       31    +1     
  Lines        3416     3425    +9     
  Branches     3416     3425    +9     
=======================================
+ Hits         3303     3312    +9     
  Misses        109      109           
  Partials        4        4           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haraldmaida haraldmaida merged commit 05ce7a3 into main Jun 8, 2025
18 checks passed
@haraldmaida haraldmaida deleted the chore/use-fakeenv-for-testing-environment-variable-specific-functionality branch June 8, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development An internal change related to development of this codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant