The answers that come up are either:
- You can manually test it
- You can use the testcase system
I could be wrong, though.
- You can write your logic as Python code (in a .py file) and import the module into your Ren'Py scripts, while writing your tests outside of Ren'Py
After seeing a few posts about it, I figured the documentation might be outdated, so I went ahead and wrote a Python module with a simple data class, imported it into my Ren'Py scripts, and tried doing basic save, load, and rollback operations, but it resulted in broken data (just like the docs suggested).
Here's the class, for those curious (there's nothing special about it):
Code: Select all
# Python .py file
class DataObject:
def __init__(self):
self.a = 0
self.b = 0
Code: Select all
# Ren'Py .rpy file
init python:
from MyModule.MyFile import DataObject
default data = DataObject()
---
So, I just want to make sure I fully understand the limitations of using Python modules inside Ren'Py files here (and that I'm not just missing something obvious):
- If I want to write unit tests, I need to use external Python modules (because there's no way to test Ren'Py code using testing libraries like pytest).
- I can't define "data" classes in Python modules, because they won't work with Ren'Py's serialization features. I need to define "data" classes in Ren'Py script files.
- I can define "pure logic" classes/functions in Python modules, and use define to instantiate the classes in my Ren'Py scripts (since they're not supposed to store any data).
- Because of the previous points, I'll need to pass my "data" classes to my "logic" classes' functions, and make sure they don't store any references for future use.
- Because my "data" classes are defined in my Ren'Py code, I'll need to mock/stub the "data" classes in my unit tests (since I can't import code from an .rpy file into a .py file).
I'd rather not go all in on this and learn that I've been missing something this whole time, haha.