When you talk about production and testing, then I would assume, you would maintain two seperate instances of your service side-by-side. One for testing and one for production. That's because you typically do not want to have to shut down your production application just for testing a new version.
So I would start two instances, one with TEST_MODE and one with PRODUCTION set. You could do that by running your python script twice, you'll probably want to create two batch files that first set the correct ENV variables and then run the frontend and backend scripts. Depending on those two ENV variables, you set a different database URL as well as a different frontend URL.