{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/438","repository_url":"https://api.github.com/repos/pytest-dev/pytest-django","labels_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/438/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/438/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/438/events","html_url":"https://github.com/pytest-dev/pytest-django/issues/438","id":193748065,"number":438,"title":"Loading of Django signals","user":{"login":"jamescooke","id":781059,"avatar_url":"https://avatars.githubusercontent.com/u/781059?v=3","gravatar_id":"","url":"https://api.github.com/users/jamescooke","html_url":"https://github.com/jamescooke","followers_url":"https://api.github.com/users/jamescooke/followers","following_url":"https://api.github.com/users/jamescooke/following{/other_user}","gists_url":"https://api.github.com/users/jamescooke/gists{/gist_id}","starred_url":"https://api.github.com/users/jamescooke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamescooke/subscriptions","organizations_url":"https://api.github.com/users/jamescooke/orgs","repos_url":"https://api.github.com/users/jamescooke/repos","events_url":"https://api.github.com/users/jamescooke/events{/privacy}","received_events_url":"https://api.github.com/users/jamescooke/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-06T11:26:39Z","updated_at":"2016-12-15T07:10:51Z","closed_at":"2016-12-15T07:10:51Z","body":"In a test suite I'm working with, there are a couple of models that have immutable UUID fields - this protection is provided by a `pre_save` signal in the Django app. It looks like this:\r\n\r\n```py\r\n@receiver(pre_save, sender=PullRequest)\r\ndef check_change_uuid(sender, instance, **kwargs):\r\n    \"\"\"\r\n    Before model that entends UUIDModel is saved, ensure that its UUID has not\r\n    changed.\r\n\r\n    Raises:\r\n        ValidationError: If uuid of the model has been found to change.\r\n    \"\"\"\r\n    ...\r\n```\r\n\r\nTo ensure that this is wired in correctly I have a test that attempts to change the UUID field in the `PullRequest` instance which expects a `ValidationError` to be raised:\r\n\r\n```py\r\n@pytest.mark.django_db\r\ndef test_uuid_permanent():\r\n    \"\"\"\r\n    PullRequest instances have immutable UUIDs\r\n\r\n    Trusts:\r\n        test_signals: A helpful message is raised.\r\n    \"\"\"\r\n    repo = PullRequest.objects.create(\r\n        repository=RepositoryFactory(),\r\n    )\r\n    repo.uuid = uuid.uuid4()\r\n\r\n    with pytest.raises(ValidationError):\r\n        repo.save()\r\n```\r\n\r\nThis test fails when run in isolation - but passes when the whole suite is run.\r\n\r\nIn order to fix the test to work in isolation, I've explicitly imported the signals at the top of the test file:\r\n\r\n```py\r\nfrom ...signals import check_change_uuid\r\n```\r\n\r\n... and the test passes again.\r\n\r\n**What is the correct way with `pytest-django` to turn on Django signals for a test?**\r\n\r\nI've searched the docs and the Issues, but can't find the official way to ensure that Signals are active - is there a fixture for that which I'm missing?"},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/comments/267255374","html_url":"https://github.com/pytest-dev/pytest-django/issues/438#issuecomment-267255374","issue_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/438","id":267255374,"user":{"login":"pelme","id":20529,"avatar_url":"https://avatars.githubusercontent.com/u/20529?v=3","gravatar_id":"","url":"https://api.github.com/users/pelme","html_url":"https://github.com/pelme","followers_url":"https://api.github.com/users/pelme/followers","following_url":"https://api.github.com/users/pelme/following{/other_user}","gists_url":"https://api.github.com/users/pelme/gists{/gist_id}","starred_url":"https://api.github.com/users/pelme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelme/subscriptions","organizations_url":"https://api.github.com/users/pelme/orgs","repos_url":"https://api.github.com/users/pelme/repos","events_url":"https://api.github.com/users/pelme/events{/privacy}","received_events_url":"https://api.github.com/users/pelme/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T07:10:51Z","updated_at":"2016-12-15T07:10:51Z","body":"The proper location is `ready()` in your app. See the note Django's signal documentation in \"Where should this code live?\":\r\nhttps://docs.djangoproject.com/en/1.10/topics/signals/#connecting-receiver-functions\r\n\r\npytest-django will call `django.setup()` which will in turn invoke `ready()`."}}
{"actor":{"display_login":"pelme"}}