From feaed7ea00bcae83bebf0844ca4ee8e1bd1f83a6 Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Tue, 13 May 2025 07:49:43 +0000 Subject: [PATCH] Docs: tests: add naming / file naming conventions (#4982) * Docs: tests: add naming / file naming conventions Deprecates putting stuff into `__init__.py`. This may be relevant for test discovery in the future. * Docs: tests: fix class naming * Docs: tests: update examples * Punctuation is hard Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Revert part of one suggestion The first set of () make the sentence make less sense. * Docs: tests: clarify that __init__.py may be empty * Make sentence nicer to read I simply kept the original wording, but I agree that it reads somewhat odd Co-authored-by: Ixrec --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Co-authored-by: Ixrec --- docs/tests.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/tests.md b/docs/tests.md index 13d62b01..78cedbc5 100644 --- a/docs/tests.md +++ b/docs/tests.md @@ -11,8 +11,13 @@ found in the [general test directory](/test/general). ## Defining World Tests In order to run tests from your world, you will need to create a `test` package within your world package. This can be -done by creating a `test` directory with a file named `__init__.py` inside it inside your world. By convention, a base -for your world tests can be created in this file that you can then import into other modules. +done by creating a `test` directory inside your world with an (empty) `__init__.py` inside it. By convention, a base +for your world tests can be created in `bases.py` or any file that does not start with `test`, that you can then import +into other modules. All tests should be defined in files named `test_*.py` (all lower case) and be member functions +(named `test_*`) of classes (named `Test*` or `*Test`) that inherit from `unittest.TestCase` or a test base. + +Defining anything inside `test/__init__.py` is deprecated. Defining TestBase there was previously the norm; however, +it complicates test discovery because some worlds also put actual tests into `__init__.py`. ### WorldTestBase @@ -21,7 +26,7 @@ interactions in the world interact as expected, you will want to use the [WorldT comes with the basics for test setup as well as a few preloaded tests that most worlds might want to check on varying options combinations. -Example `/worlds//test/__init__.py`: +Example `/worlds//test/bases.py`: ```python from test.bases import WorldTestBase @@ -49,7 +54,7 @@ with `test_`. Example `/worlds//test/test_chest_access.py`: ```python -from . import MyGameTestBase +from .bases import MyGameTestBase class TestChestAccess(MyGameTestBase):