There is no such config, but you can make it through socket interface 
mocking 
https://stackoverflow.com/questions/18601828/python-block-network-connections-for-testing-purposes

You can also split all tests into two groups:
- unit tests - should run without internet and all required requests should 
be mocked
- integration tests - should run with internet as in production system

For integration tests you can use decorator skipUnless  (from unittest 
import skipUnless)

You can have settings_test.py and settings_integration_tests
for example, there can be a parameter in settings 
INTEGRATION_TESTS = True (or False in unit test settings)

and then, test functions can be decorated like

@skipUnless(settings.INTEGRATION_TESTS)


On Monday, 23 July 2018 19:04:48 UTC+8, Kum wrote:
>
> Hi,
>
> Is there a global config I can enable to prevent any Django tests in a 
> project from accessing the internet (i.e., only allow network calls to 
> localhost) ?
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d457e8a-34a8-4f8f-8a27-99f05e31dffc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to