mongoengine connect() in settings.py testing problem

后端 未结 4 603
忘掉有多难
忘掉有多难 2021-02-06 04:29

I want to be able to do conditional connect() based on either I started django in testing mode or not.

in my settings.py I use mongoengine connect() method to connect to

4条回答
  •  迷失自我
    2021-02-06 05:25

    While it is possible to do that, it is easier and common practice to have 2 settings files. One possible configuration could be:

    You have 2 settings files, lsettings.py that doesn't connect and settings.py that does

    from lsettings import *
    mongodb.connect()
    

    So, while locally testing you can:

    python manage.py test --settings=lsettings
    

    And it doesn't connect.

    tl;dr: It is easier to manage configuration differences by having multiple configuration files that import each other conditionally rather than trying to have conditional parameters within the same settings file. YMMV.

提交回复
热议问题