You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. """
  2. This weirdness exists to work around a very specific problem
  3. with testing WX: you can only ever have one App() instance per
  4. process. I've spent hours and hours trying to work around this and
  5. figure out how to gracefully destroy and recreate them, but... no dice.
  6. This is echo'd in the docs: https://wxpython.org/Phoenix/docs/html/wx.App.html
  7. Destroying/recreating causes instability in the tests. We can work around that
  8. by reusing the same App instance across tests and only destroying the top level
  9. frame (which is fine). However, this causes a new problem: the last test which
  10. runs will now always fail, cause we're not Destroying the App instance.
  11. Ideal world: UnitTest would expose a global "done" hook regardless of test
  12. discovery type. That doesn't exist, so the best we can do is use the Module cleanup
  13. methods. These aren't perfect, but destroying / recreating at the module boundary
  14. gives slightly more reliable tests. These are picked up by the test runner
  15. by their existence in the module's globals(). There's no other way to hook
  16. things together. We need it in every test, and thus... that's the background
  17. for why this weirdness is going on.
  18. It's a hack around a hack around a problem in Wx.
  19. Usage:
  20. In any tests which use WX, you must import this module's definitions
  21. into the test's global scope
  22. ```
  23. from gooey.tests import *
  24. ```
  25. """
  26. import wx
  27. app = None
  28. def setUpModule():
  29. global app
  30. app = wx.App()
  31. def tearDownModule():
  32. global app
  33. app.Destroy()