[wp-trac] [WordPress Trac] #63532: Unit Testing: Checking if images already exists before starting tests

WordPress Trac noreply at wordpress.org
Thu Jun 5 11:20:59 UTC 2025


#63532: Unit Testing: Checking if images already exists before starting tests
-------------------------------------------------+-------------------------
 Reporter:  SirLouen                             |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.9
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-test-info has-patch has-unit-    |     Focuses:  tests
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by SirLouen):

 Replying to [comment:6 SergeyBiryukov]:
 > Hi there, thanks for the ticket!
 >
 > I think a safer approach would perhaps be to delete the pre-existing
 file, otherwise there might be a collision if a test expects an attachment
 with the same name but different data.
 >
 > Ideally, each test class should be responsible for deleting any leftover
 attachments, see [41693] / #38264.

 Totally agree

 I was considering that option last night. My approach is the safest option
 but I don't love it. The thing is that it could simply serve as a failover
 in case in this or other tests related to media (not in `media.php` are
 using this helper function, but definitely I believe that also cleaning
 upload data before tests is critical as pointed out in #50209. But this
 work requires more investigation

 For now I think this could be introduced for the Setup function. I might
 consider this ticket for this afternoon during WCEU (otherwise I will
 review and add a new commit)

 @SergeyBiryukov do you think that the failover I've already implemented is
 a good idea?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63532#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list