If CodeBots Arena tests pass locally but GitHub Actions cannot import the project code, check whether the CI test process can see the directory containing the package. The incident article reports fixing this by adding the repository’s server directory to PYTHONPATH for the test step, then running python -m pytest tests/ -v. That path is specific to this repository; use the source root in your own checkout, not server by default.
Why CI can have the code but still fail to import it
A checkout can contain every source file and still produce an import error before test logic runs. Python searches locations listed in sys.path; if the directory containing an importable package is not among them, an import such as the one for the CodeBots Arena battle engine can fail. pytest likewise requires application modules to be reachable through Python’s import path. See pytest’s documentation on import mechanisms.
As an Amazon Associate I earn from qualifying purchases.
The CodeBots Arena incident article reports that its CI job did not include the project’s server-side source directory in the search path. Its reported fix was to set PYTHONPATH for the test step to ${{ github.workspace }}/server. The article says the change was recorded as commit fa401d4 and that CI then resolved the imports and proceeded to execute tests. Those are the article’s reported project-specific details; they are not an independently verified run of the repository.
Recommended Free Tools
First find the import root in your checkout
- Read the failing import and identify the package it names. In the checked-out repository, locate the directory from which that import would be valid.
- Compare that directory with the CI job’s working directory and configured search path. A nested source directory is not automatically visible merely because the repository root was checked out.
- Check that the local and CI commands use the intended Python interpreter and that dependencies are installed. GitHub recommends
setup-pythonto select Python consistently; hosted-runner default versions can vary. Its Python workflow guide shows interpreter setup, dependency installation, and pytest execution.
Do not copy the CodeBots Arena value blindly. ${{ github.workspace }}/server is correct only if server is the directory that should serve as the import root in your repository.
#1 Best Overall
Set the path in the GitHub Actions test step
For the CodeBots Arena layout described in the incident article, the relevant setting is:
env:
PYTHONPATH: ${{ github.workspace }}/server
Place this environment setting on the test step so it applies to the process running pytest. The reported invocation is:
Rank #2
python -m pytest tests/ -v
For another project, substitute its actual source root. Keep Python setup, dependency installation, and the test command explicit in the workflow; GitHub’s guide provides an example of this overall sequence.
Free tools Windows power users keep installed
One-click scans. No signup required.
Understand what changing the test command does
python -m pytest and invoking pytest directly are usually similar, but pytest documents one important distinction: python -m pytest adds the current working directory to sys.path. That can fix a mismatch when the repository root is the intended import root. It does not add an arbitrary nested directory such as server, and it cannot compensate for running from the wrong directory. The distinction is documented in pytest’s import documentation.
Choose an import strategy that matches the project
| Approach | Best fit | Tradeoff |
|---|---|---|
Set PYTHONPATH to the source root |
A project with a clear source directory that CI does not otherwise expose; this is the fix reported for CodeBots Arena. | The value depends on the repository and runner layout. A wrong path leaves the underlying layout assumption unresolved. |
Run python -m pytest |
The current working directory is intended to be importable. | It adds the current directory only; it does not expose every nested source folder. |
Install the project in CI or adopt a src layout |
A maintained package that should be tested as an installed project. | Requires deliberate packaging and installation steps. A src layout can help avoid confusion between an installed package and a local copy. |
| Change pytest import mode | A deliberate choice about how test modules should be imported. | pytest’s prepend, append, and importlib modes have different effects on module resolution; changing modes was not the reported CodeBots Arena fix. |
Check for duplicate packages and pytest import-mode effects
pytest’s default prepend mode inserts the directory containing a test module at the start of sys.path when needed. append adds it at the end, which can result in tests importing an installed package rather than a local package with the same import root. pytest notes that a src layout can help avoid this ambiguity.
The importlib mode imports test modules without changing sys.path. Its tradeoffs include that test modules cannot import one another in the usual way and helper modules under the tests directory are not automatically importable. These modes are useful diagnostic context, not a substitute for identifying the intended source root.
Separate import failures from test failures
If the error occurs during import or test collection, the test body may not have run at all. First confirm that CI resolves the intended package; only after collection succeeds should you treat later assertion failures as application-logic or test failures. For this incident, the reported problem was import-path resolution before the tests could exercise the code.
For a focused diagnosis, compare the local and CI working directories, interpreter, dependency installation, test command, and imported package location. If both an installed copy and a checkout copy exist, verify which one pytest selects before changing application code.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




