Overview
PyAutoConf's 71 unit tests take ~10.5s due to redundant conf.Config instantiation. The config fixture is function-scoped, meaning every test rebuilds the Config from disk via recursive filesystem traversal. Read-only tests can share a session-scoped config, cutting total time by ~50-60%.
This is the first repo in a series — the same profiling and optimization approach will be applied to PyAutoFit, PyAutoArray, PyAutoGalaxy, and PyAutoLens.
Plan
- Profile test suite to identify slowest tests and root causes
- Categorize tests into read-only (config lookups) vs mutating (config.push)
- Introduce session-scoped config fixture for read-only tests
- Keep function-scoped fixture for tests that mutate config state
- Verify all 71 tests pass with identical assertions — no numerical changes
Detailed implementation plan
Affected Repositories
Work Classification
Library
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoConf |
main |
2 untracked .fits |
Suggested branch: feature/speed-up-unit-tests
Implementation Steps
-
Refactor test_autoconf/conftest.py — Add a session-scoped config fixture (_shared_config) and a read-only wrapper. Keep the existing function-scoped config for mutating tests.
-
Update test_autoconf/test_default.py — Switch read-only tests (test_override_file, test_override_in_directory, test_novel_directory, test_novel_file, test_json, test_embedded_yaml_default, test_as_dict, test_mix_files) to use the shared config. Keep test_push, test_keep_first, test_logging_config on function-scoped fixture.
-
Review test_autoconf/test_config.py — All tests are read-only lookups, can use session-scoped config.
-
Review test_autoconf/test_decorator.py and test_autoconf/test_output_config.py — These have autouse fixtures that push config; analyse whether they can be scoped higher.
-
Review test_autoconf/test_dictable.py, test_autoconf/test_fitsable.py — These don't use the config fixture; no changes needed.
-
Run full test suite and compare timing before/after.
Key Files
test_autoconf/conftest.py — fixture refactoring
test_autoconf/test_default.py — largest speedup target (8 of 11 tests are read-only)
Original Prompt
Click to expand starting prompt
This is a generic source code improvement that applies to all five PyAuto repos.
Basically, some unit tests run slow, and this dev work aims to profile the unit tests and speed them up as much as possible. We don't want to change numerical values on unit tests where possible, however I am also confident currently that the source code is stable thus for the slower unit tests if there are safe changes we can make to speed them up, then we should do so, but prompt me on them.
To begin, can we run this on PyAutoConf and I'll see how it goes and we can then run it on the other repos.
Overview
PyAutoConf's 71 unit tests take ~10.5s due to redundant
conf.Configinstantiation. Theconfigfixture is function-scoped, meaning every test rebuilds the Config from disk via recursive filesystem traversal. Read-only tests can share a session-scoped config, cutting total time by ~50-60%.This is the first repo in a series — the same profiling and optimization approach will be applied to PyAutoFit, PyAutoArray, PyAutoGalaxy, and PyAutoLens.
Plan
Detailed implementation plan
Affected Repositories
Work Classification
Library
Branch Survey
Suggested branch:
feature/speed-up-unit-testsImplementation Steps
Refactor
test_autoconf/conftest.py— Add asession-scoped config fixture (_shared_config) and a read-only wrapper. Keep the existing function-scopedconfigfor mutating tests.Update
test_autoconf/test_default.py— Switch read-only tests (test_override_file,test_override_in_directory,test_novel_directory,test_novel_file,test_json,test_embedded_yaml_default,test_as_dict,test_mix_files) to use the shared config. Keeptest_push,test_keep_first,test_logging_configon function-scoped fixture.Review
test_autoconf/test_config.py— All tests are read-only lookups, can use session-scoped config.Review
test_autoconf/test_decorator.pyandtest_autoconf/test_output_config.py— These have autouse fixtures that push config; analyse whether they can be scoped higher.Review
test_autoconf/test_dictable.py,test_autoconf/test_fitsable.py— These don't use the config fixture; no changes needed.Run full test suite and compare timing before/after.
Key Files
test_autoconf/conftest.py— fixture refactoringtest_autoconf/test_default.py— largest speedup target (8 of 11 tests are read-only)Original Prompt
Click to expand starting prompt
This is a generic source code improvement that applies to all five PyAuto repos.
Basically, some unit tests run slow, and this dev work aims to profile the unit tests and speed them up as much as possible. We don't want to change numerical values on unit tests where possible, however I am also confident currently that the source code is stable thus for the slower unit tests if there are safe changes we can make to speed them up, then we should do so, but prompt me on them.
To begin, can we run this on PyAutoConf and I'll see how it goes and we can then run it on the other repos.