The solution is based on monkeypatch fixture.
In this example myprog
reads number from the file myprog_input.txt
adds 2
to it and stores result in myprog_output.txt
uname -vosri
Linux 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 GNU/Linux
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
python3.11 --version
Python 3.11.7