Closed jwallwork23 closed 4 months ago
You mentioned on the meeting that you don't really like the use of sed
here. How about this instead:
demo.py:
end_time = 2000.0
print("end time", end_time)
test_demo.py
def test_demo(capsys):
with open('demo.py', 'r') as file:
demo_content = file.read()
modified_demo_content = demo_content.replace('end_time = 2000.0', 'end_time = 10.0')
exec(modified_demo_content)
# Capture the print output to check that it worked
captured = capsys.readouterr()
assert "end time 10.0" in captured.out
Essentially the same thing, but more flexible and avoids changing the original script (I guess we'd have to create a copy of the script before using sed
).
Nice! Yes, that's much more Pythonic and would be a better approach.
Rather than confusing the demo content with environment variables, we should apply specific modifications with
sed
when running the test suite.