Opened 13 months ago

Last modified 13 months ago

#27447 assigned New feature

Provide an easy way to test sending of signals

Reported by: James Bennett Owned by: James Bennett
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Currently, when writing tests for an application that sends signals, there's no easy built-in way to test the sending of signals.

A simple solution would be to add a context-manager assertion that can check a signal was sent and received keyword arguments with certain names, and then further inspection of the received arguments could be done inside the with block. For example:

with self.AssertSignalSent(some_signal, required_kwargs=['my_kwarg']):
    # ...do stuff...

Change History (7)

comment:1 Changed 13 months ago by Josh Smeaton

Triage Stage: UnreviewedAccepted
Version: 1.10master

comment:2 Changed 13 months ago by James Bennett

Owner: changed from nobody to James Bennett
Status: newassigned

comment:3 Changed 13 months ago by Tim Graham

Has patch: set
Patch needs improvement: set

WIP PR

comment:6 Changed 13 months ago by James Bennett

Triage Stage: AcceptedReady for checkin

comment:7 Changed 13 months ago by Simon Charette

Patch needs improvement: unset
Triage Stage: Ready for checkinAccepted

The code is looking good. Let's wait for a documentation review from a native speaker.

comment:8 Changed 13 months ago by James Bennett

Triage Stage: AcceptedReady for checkin

We're now at four other members of -core reviewed, all concerns addressed. Speak now or implement fixes for your critique later.

comment:9 Changed 13 months ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

I left some comments on the PR. When James is finished with the updates, I'll add a commit to the branch that makes use of this assertion in Django's test suite.

Note: See TracTickets for help on using tickets.
Back to Top