pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.2k stars 328 forks source link

Issues with unit tests #696

Open DustanBower opened 2 months ago

DustanBower commented 2 months ago

Not sure if this is a bug report, feature request, or request for documentation, but I'm having issues with unit tests and ursina.

I'd like to write some tests to test my physics code for a 2d game I'm working on. My current iteration process makes it easy to introduce physics bugs that I don't notice right away, and I'd like to have tests to ensure later changes don't break things.

I'm using pytest, and I'm completely stumped on getting tests to work. I don't have any errors. My current attempt just tries to load and run the game without even testing anything. I have a main() function which just does my game setup and runs app.run(). I call main() in the test. The game appears, but doesn't do anything and doesn't respond to input. The update() function doesn't appear to be called unless I manually call it. I'm importing everything from ursina (from ursina import *) as the documentation recommends.

Initially I thought it might be a namespace issue of some kind, but I'm doing the same imports in my actual game as I am in my tests. I don't see any unit tests examples in the code or documentation that I could use as guidelines either.

DustanBower commented 2 months ago

The issue here is that it wasn't clear to me how the global update() function was called.

I was able to fix it by importing my update function and then setting:

import __main__
__main__.update = update

I haven't needed to do the same with input, but it looks like it should work the same, as the code that calls update() and input() are similar.