Skip to content

Conversation

laundry-96
Copy link
Contributor

@laundry-96 laundry-96 commented Aug 19, 2025

fix #864

The environment variables were not overridden from the .testcontainers.properties file for ryuk variables. This causes the properties file to never actually be used. This commit detects the environment variable, and if unspecified falls back to the properties file, and if not specified, defaults to false

@alexanderankin alexanderankin changed the title Fix improper reading of .testcontainers.properties fix(core): improper reading of .testcontainers.properties Aug 19, 2025
@alexanderankin
Copy link
Member

see if you can make the tests pass? i can take a look to see if i can finish this pr when i am available

The environment variables were not overridden from the .testcontainers.properties file for ryuk variables.
This causes the properties file to never actually be used.
This commit detects the environment variable, and if unspecified falls back to the properties file, and if not specifed, defaults to false
@laundry-96
Copy link
Contributor Author

@alexanderankin I fixed it by adding a Optional[bool] defaulted to None, which allows an override for ryuk_disabled and ryuk_privileged programmatically.

Sorry for not reading the CONTRIBUTING.md. I didn't see it in the top level directory and didn't see the README.md 😅

I'm on a mac, so the test is set to skipped, but I disabled that and it seems to have passed. I can't be too sure until I see the tests here though.

Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@b21e5e3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
core/testcontainers/core/config.py 93.10% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #863   +/-   ##
=======================================
  Coverage        ?   82.09%           
=======================================
  Files           ?       14           
  Lines           ?      916           
  Branches        ?      148           
=======================================
  Hits            ?      752           
  Misses          ?      128           
  Partials        ?       36           

☔ 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.

Removed unused method get_bool_env, as it was replaced with _render_bool
Added more tests for proper test coverage for loading variables via testcontainers.properties file
@laundry-96
Copy link
Contributor Author

@alexanderankin Can I get one more run please? I have added some extra test cases and caught some errors myself :)

@laundry-96
Copy link
Contributor Author

@alexanderankin It seems like the docs build failed due to a connection failure? Mind triggering again?

@alexanderankin
Copy link
Member

can you tldr what this code does? im on a work trip right now and just dont have time this week to look at this - i would merge otherwise

@laundry-96
Copy link
Contributor Author

laundry-96 commented Aug 26, 2025

TLDR: Originally when running test containers, you can set variables inside of ~/.testcontainers.properties and it should be picked up to look at settings, if the corresponding environment variables are not set.

What was happening originally was that the ryuk_privileged and ryuk_disabled would read the environment, and if it wasn't set, it would default to False. And because the variable is set, it doesn't actually inherit the properties file.

Function causing this issue:

def get_bool_env(name: str) -> bool:
    """
    Get environment variable named `name` and convert it to bool.
    Defaults to False.
    """
    value = environ.get(name, "")
    return value.lower() in ("yes", "true", "t", "y", "1")

As you can see this would return either True or False.

What my change does, is bring this function into the class, and when attempting to access the disabled or privileged class value, it calculates it based on if it was set previously (via code, env, or properties file), and if not then checks the environment, then checks the properties file, then defaults to False

Also, I totally understand being busy! I just want to say thank you so much for providing this package from your own time and energy :)

@alexanderankin alexanderankin merged commit 350f246 into testcontainers:main Aug 27, 2025
10 of 11 checks passed
@laundry-96 laundry-96 deleted the patch-2 branch August 27, 2025 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: .testcontainers.properties file not properly used
2 participants