Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0eeb705

Browse files
dmitry-lipetskvshepard
and
vshepard
authored
Tests are based on pytest (#192)
* Using pytest [pytest.raises]* Using pytest [pytest.skip]* Using pytest [assertIsNotNone]* Using pytest [assertFalse]* Using pytest [assertTrue]* Using pytest [assertEqual]* Using pytest [assertNotEqual]* Using pytest [assertGreaterEqual]* Using pytest [assertGreater]* Using pytest [assertIn]* Using pytest [assertListEqual]* unittest is not used* Code style (flake8)* Execution signature is removed* run_tests.sh installs pytest* run_tests.sh is updatedrun tests through pytest explicitly* Total refactoring of tests- TestgresRemoteTests does not use global variables and code- Explicit work with ..testgres folder* Code style (flake8)* Root __init__.py is addedIt is required for tests.* Code style (flake8)* pytest.ini is added* TestgresTests::test_ports_management is correctedLet's send warning about a garbage in the container "bound_ports" and continue working.* coding: utf-8* Cleanup* CI runs all the tests of testgres.* Add install ssh(cherry picked from commitfec1e7a)* Revert "Add install ssh"This reverts commit537a9ac.* Revert "CI runs all the tests of testgres."This reverts commit2d2532c.* Test of probackup plugin is restoredIt works now (was runned with a fresh probackup2 and vanilla 18devel).* The test suite of a probackup plugin is based on pytest* Probackup plugin is updatedProbackup plugin tests - They are skipped if PGPROBACKUPBIN is not definedGlobal variable init_params is None when PGPROBACKUPBIN is not defined or version is not processed* CI test use 4 cores* testgres.plugins.probackup2.Init was restored [thanks to Yuri Sokolov]* pytest.ini is updated [testpaths]Enumeration of all the known folders with tests.* test_child_pids (local, remote) is updatedMultiple attempts and logging are added.* test_child_process_dies is updatedMultiple attempts are added.---------Co-authored-by: vshepard <v.shepard@postgrespro.ru>
1 parent669e134 commit0eeb705

File tree

13 files changed

+839
-617
lines changed

13 files changed

+839
-617
lines changed

‎__init__.py

Whitespace-only changes.

‎pytest.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[pytest]
2+
testpaths = ["./tests","./testgres/plugins/pg_probackup2/pg_probackup2/tests"]
3+
addopts = --strict-markers
4+
markers =
5+
#log_file = logs/pytest.log
6+
log_file_level = NOTSET
7+
log_file_format = %(levelname)8s [%(asctime)s] %(message)s
8+
log_file_date_format=%Y-%m-%d %H:%M:%S
9+

‎run_tests.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export VIRTUAL_ENV_DISABLE_PROMPT=1
2222
source$VENV_PATH/bin/activate
2323

2424
# install utilities
25-
$PIP install coverage flake8 psutil Sphinx
25+
$PIP install coverage flake8 psutil Sphinx pytest pytest-xdist psycopg2 six psutil
2626

2727
# install testgres' dependencies
2828
export PYTHONPATH=$(pwd)
29-
$PIP install.
29+
#$PIP install .
3030

3131
# test code quality
3232
flake8.
@@ -38,21 +38,19 @@ rm -f $COVERAGE_FILE
3838

3939

4040
# run tests (PATH)
41-
time coverage run -atests/test_simple.py
41+
time coverage run -a-m pytest -l -v -n 4 -k"TestgresTests"
4242

4343

4444
# run tests (PG_BIN)
4545
time \
4646
PG_BIN=$(dirname$(which pg_config)) \
47-
ALT_CONFIG=1 \
48-
coverage run -a tests/test_simple.py
47+
coverage run -a -m pytest -l -v -n 4 -k"TestgresTests"
4948

5049

5150
# run tests (PG_CONFIG)
5251
time \
5352
PG_CONFIG=$(which pg_config) \
54-
ALT_CONFIG=1 \
55-
coverage run -a tests/test_simple.py
53+
coverage run -a -m pytest -l -v -n 4 -k"TestgresTests"
5654

5755

5856
# show coverage

‎testgres/plugins/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
frompg_probackup2.gdbimportGDBobj
2-
frompg_probackup2.appimportProbackupApp,ProbackupException
3-
frompg_probackup2.init_helpersimportinit_params
4-
frompg_probackup2.storage.fs_backupimportFSTestBackupDir
1+
from.pg_probackup2.pg_probackup2.gdbimportGDBobj
2+
from.pg_probackup2.pg_probackup2.appimportProbackupApp,ProbackupException
3+
from.pg_probackup2.pg_probackup2.init_helpersimportinit_params
4+
from.pg_probackup2.pg_probackup2.storage.fs_backupimportFSTestBackupDir
55

66
__all__= [
77
"ProbackupApp","ProbackupException","init_params","FSTestBackupDir","GDBobj"

‎testgres/plugins/pg_probackup2/pg_probackup2/init_helpers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def __init__(self):
121121
self.probackup_path=probackup_path_tmp
122122

123123
ifnotself.probackup_path:
124-
logging.error('pg_probackup binary is not found')
125-
exit(1)
124+
raiseException('pg_probackup binary is not found')
126125

127126
ifos.name=='posix':
128127
self.EXTERNAL_DIRECTORY_DELIMITER=':'
@@ -213,11 +212,15 @@ def __init__(self):
213212
ifself.probackup_version.split('.')[0].isdigit():
214213
self.major_version=int(self.probackup_version.split('.')[0])
215214
else:
216-
logging.error('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(self.probackup_version))
217-
sys.exit(1)
215+
raiseException('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(self.probackup_version))
218216

219217
deftest_env(self):
220218
returnself._test_env.copy()
221219

222220

223-
init_params=Init()
221+
try:
222+
init_params=Init()
223+
exceptExceptionase:
224+
logging.error(str(e))
225+
logging.warning("testgres.plugins.probackup2.init_params is set to None.")
226+
init_params=None

‎testgres/plugins/pg_probackup2/pg_probackup2/tests/__init__.py

Whitespace-only changes.

‎testgres/plugins/pg_probackup2/pg_probackup2/tests/basic_test.py

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from __future__importannotations
2+
3+
importos
4+
importshutil
5+
importpytest
6+
7+
from ......importtestgres
8+
from ...pg_probackup2.appimportProbackupApp
9+
from ...pg_probackup2.init_helpersimportInit,init_params
10+
from ..storage.fs_backupimportFSTestBackupDir
11+
12+
13+
classProbackupTest:
14+
pg_node:testgres.PostgresNode
15+
16+
@staticmethod
17+
defprobackup_is_available()->bool:
18+
p=os.environ.get("PGPROBACKUPBIN")
19+
20+
ifpisNone:
21+
returnFalse
22+
23+
ifnotos.path.exists(p):
24+
returnFalse
25+
26+
returnTrue
27+
28+
@pytest.fixture(autouse=True,scope="function")
29+
defimplicit_fixture(self,request:pytest.FixtureRequest):
30+
assertisinstance(request,pytest.FixtureRequest)
31+
self.helper__setUp(request)
32+
yield
33+
self.helper__tearDown()
34+
35+
defhelper__setUp(self,request:pytest.FixtureRequest):
36+
assertisinstance(request,pytest.FixtureRequest)
37+
38+
self.helper__setup_test_environment(request)
39+
self.helper__setup_test_paths()
40+
self.helper__setup_backup_dir()
41+
self.helper__setup_probackup()
42+
43+
defhelper__setup_test_environment(self,request:pytest.FixtureRequest):
44+
assertisinstance(request,pytest.FixtureRequest)
45+
46+
self.output=None
47+
self.cmd=None
48+
self.nodes_to_cleanup= []
49+
self.module_name,self.fname=request.node.cls.__name__,request.node.name
50+
self.test_env=Init().test_env()
51+
52+
defhelper__setup_test_paths(self):
53+
self.rel_path=os.path.join(self.module_name,self.fname)
54+
self.test_path=os.path.join(init_params.tmp_path,self.rel_path)
55+
os.makedirs(self.test_path,exist_ok=True)
56+
self.pb_log_path=os.path.join(self.test_path,"pb_log")
57+
58+
defhelper__setup_backup_dir(self):
59+
self.backup_dir=self.helper__build_backup_dir('backup')
60+
self.backup_dir.cleanup()
61+
62+
defhelper__setup_probackup(self):
63+
self.pg_node=testgres.NodeApp(self.test_path,self.nodes_to_cleanup)
64+
self.pb=ProbackupApp(self,self.pg_node,self.pb_log_path,self.test_env,
65+
auto_compress_alg='zlib',backup_dir=self.backup_dir)
66+
67+
defhelper__tearDown(self):
68+
ifos.path.exists(self.test_path):
69+
shutil.rmtree(self.test_path)
70+
71+
defhelper__build_backup_dir(self,backup='backup'):
72+
returnFSTestBackupDir(rel_path=self.rel_path,backup=backup)
73+
74+
75+
@pytest.mark.skipif(notProbackupTest.probackup_is_available(),reason="Check that PGPROBACKUPBIN is defined and is valid.")
76+
classTestBasic(ProbackupTest):
77+
deftest_full_backup(self):
78+
# Setting up a simple test node
79+
node=self.pg_node.make_simple('node',pg_options={"fsync":"off","synchronous_commit":"off"})
80+
81+
# Initialize and configure Probackup
82+
self.pb.init()
83+
self.pb.add_instance('node',node)
84+
self.pb.set_archiving('node',node)
85+
86+
# Start the node and initialize pgbench
87+
node.slow_start()
88+
node.pgbench_init(scale=100,no_vacuum=True)
89+
90+
# Perform backup and validation
91+
backup_id=self.pb.backup_node('node',node)
92+
out=self.pb.validate('node',backup_id)
93+
94+
# Check if the backup is valid
95+
assertf"INFO: Backup{backup_id} is valid"inout

‎tests/helpers/run_conditions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding: utf-8
12
importpytest
23
importplatform
34

‎tests/test_local.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# coding: utf-8
12
importos
23

34
importpytest
45
importre
56
importtempfile
67

7-
fromtestgresimportExecUtilException
8-
fromtestgresimportInvalidOperationException
9-
fromtestgresimportLocalOperations
8+
from..testgresimportExecUtilException
9+
from..testgresimportInvalidOperationException
10+
from..testgresimportLocalOperations
1011

1112
from .helpers.run_conditionsimportRunConditions
1213

‎tests/test_remote.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
# coding: utf-8
12
importos
23

34
importpytest
45
importre
56
importtempfile
67

7-
fromtestgresimportExecUtilException
8-
fromtestgresimportInvalidOperationException
9-
fromtestgresimportRemoteOperations
10-
fromtestgresimportConnectionParams
8+
from..testgresimportExecUtilException
9+
from..testgresimportInvalidOperationException
10+
from..testgresimportRemoteOperations
11+
from..testgresimportConnectionParams
1112

1213

1314
classTestRemoteOperations:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp