The environment variable PYTHONWARNINGS only works with the python interpreter binary, but not with programs embedding libpython. This could be changed by moving the code from Modules/main.c to Python/pythonrun.c. See attached patch (compiles cleanly, tests pass, not tested on Windows). (I have checked all the other environment variables listed on the python man page for whether those that could be usable in the library are actually processed in the library, and all but PYTHONWARNINGS appear to behave reasonably.)
Can we have a patch review please, I'm not touching C code at that level within Python. Are people happy with the concept of moving code from main.c to pythonrun.c ?
I refactored deeply Modules/main.c and moved the code to Python/initconfig.c and Python/preconfig.c. There is now a public C API to access to all configuration parameters documented at: https://docs.python.org/dev/c-api/init_config.html The design document is the PEP 587 which has been implemented in Python 3.8. If you use the "Python Configuration", you now get the same behaviour than system Python program ("python"). Or you can use "Isolated Configuration" but opt-in for environment variables. Or you can modify PyConfig.warnoptions: https://docs.python.org/dev/c-api/init_config.html#c.PyConfig.warnoptions So you know have plently of choices to use PYTHONWARNINGS env var when you embed Python. Good news: Python 3.8 beta4 is now available for testing!