Python mock Patch os.environ and return value

前端 未结 4 1194
孤独总比滥情好
孤独总比滥情好 2020-12-05 12:46

Unit testing conn() using mock:

app.py

import mysql.connector
import os, urlparse


def conn():
    if "DAT         


        
4条回答
  •  时光取名叫无心
    2020-12-05 13:12

    You can also use something like the modified_environ context manager describe in this question to set/restore the environment variables.

    with modified_environ(DATABASE_URL='mytemp'):
        func()
    

提交回复
热议问题