Skip to content

Commit b597bf8

Browse files
Warnings with pytest are fixed (#223)
1) [pytest.ini] testpaths has another format. It is a spaces separated list. pytest warning: PytestConfigWarning: No files were found in testpaths; consider removing or adjusting your testpaths configuration. Searching recursively from the current directory instead. 2) pytest tries to find the test function in TestgresException class. Let's rename it to avoid this problem. pytest warning: PytestCollectionWarning: cannot collect test class 'TestgresException' because it has a __init__ constructor (from: tests/test_simple.py) class TestgresException(Exception): Of course, we can add __test__=False in TestgresException but it is not a good solution.
1 parent 0b2c629 commit b597bf8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
testpaths = ["./tests", "./testgres/plugins/pg_probackup2/pg_probackup2/tests"]
2+
testpaths = tests testgres/plugins/pg_probackup2/pg_probackup2/tests
33
addopts = --strict-markers
44
markers =
55
#log_file = logs/pytest.log

tests/test_testgres_common.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
from ..testgres import ProcessType
1111
from ..testgres import NodeStatus
1212
from ..testgres import IsolationLevel
13-
from ..testgres import TestgresException
13+
14+
# New name prevents to collect test-functions in TestgresException and fixes
15+
# the problem with pytest warning.
16+
from ..testgres import TestgresException as testgres_TestgresException
17+
1418
from ..testgres import InitNodeException
1519
from ..testgres import StartNodeException
1620
from ..testgres import QueryException
@@ -336,7 +340,7 @@ def LOCAL__check_auxiliary_pids__multiple_attempts(
336340
with __class__.helper__get_node(os_ops).init().start() as master:
337341

338342
# master node doesn't have a source walsender!
339-
with pytest.raises(expected_exception=TestgresException):
343+
with pytest.raises(expected_exception=testgres_TestgresException):
340344
master.source_walsender
341345

342346
with master.connect() as con:
@@ -366,7 +370,7 @@ def LOCAL__check_auxiliary_pids__multiple_attempts(
366370
replica.stop()
367371

368372
# there should be no walsender after we've stopped replica
369-
with pytest.raises(expected_exception=TestgresException):
373+
with pytest.raises(expected_exception=testgres_TestgresException):
370374
replica.source_walsender
371375

372376
def test_exceptions(self):
@@ -1013,7 +1017,7 @@ def test_replication_slots(self, os_ops: OsOperations):
10131017
replica.execute('select 1')
10141018

10151019
# cannot create new slot with the same name
1016-
with pytest.raises(expected_exception=TestgresException):
1020+
with pytest.raises(expected_exception=testgres_TestgresException):
10171021
node.replicate(slot='slot1')
10181022

10191023
def test_incorrect_catchup(self, os_ops: OsOperations):
@@ -1022,7 +1026,7 @@ def test_incorrect_catchup(self, os_ops: OsOperations):
10221026
node.init(allow_streaming=True).start()
10231027

10241028
# node has no master, can't catch up
1025-
with pytest.raises(expected_exception=TestgresException):
1029+
with pytest.raises(expected_exception=testgres_TestgresException):
10261030
node.catchup()
10271031

10281032
def test_promotion(self, os_ops: OsOperations):

0 commit comments

Comments
 (0)