mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-04 12:02:55 +00:00
Use pytest to manage background services, paths, and environment variables. Benefits: - Tests are a little easier to write. - Cleanup is more reliable. You can CTRL-C a test and it will still shut down gracefully. If you manually start a conflicting process, the test fixtures will detect this and abort at startup. - Don't need to worry about remembering '--test-threads=1' - Output of sub-processes can be captured to files. - Test fixtures configure everything to operate under a single test output directory, making it easier to capture logs in CI. - Detects all the necessary paths if run from the git root, but can also run from arbitrary paths by setting environment variables. There is also a deliberately broken test (test_broken.py) that can be used to test whether the test fixtures properly clean up after themselves. It won't run by default; the comment at the top explains how to enable it.
35 lines
807 B
Python
35 lines
807 B
Python
import pytest
|
|
import os
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
"""
|
|
|
|
Use this test to see what happens when tests fail.
|
|
|
|
We should be able to clean up after ourselves, including stopping any
|
|
postgres or pageserver processes.
|
|
|
|
Set the environment variable RUN_BROKEN to see this test run (and fail,
|
|
and hopefully not leave any server processes behind).
|
|
|
|
"""
|
|
|
|
|
|
run_broken = pytest.mark.skipif(
|
|
os.environ.get('RUN_BROKEN') == None,
|
|
reason="only used for testing the fixtures"
|
|
)
|
|
|
|
@run_broken
|
|
def test_broken(zenith_cli, pageserver, postgres, pg_bin):
|
|
zenith_cli.run_init()
|
|
pageserver.start()
|
|
print('pageserver is running')
|
|
|
|
postgres.create_start()
|
|
print('postgres is running')
|
|
|
|
print('THIS NEXT COMMAND WILL FAIL:')
|
|
pg_bin.run('pgbench -i_am_a_broken_test'.split())
|