Coverage for tests/tests_pkg_one/test_one.py: 88%
25 statements
« prev ^ index » next coverage.py v7.2.1, created at 2024-07-25 16:40 +0300
« prev ^ index » next coverage.py v7.2.1, created at 2024-07-25 16:40 +0300
1"""
3Example tests for package one module one
5"""
7import sys
8import datetime
9import pytest
10import pdb
13@pytest.mark.one
14@pytest.mark.xdist_group(name="group1")
15class TestsOne:
16 """
17 All tests will run on the same worker if you pass '--dist loadgroup'
18 """
20 shared_items = []
21 failed_tests = []
23 # @pytest.hookimpl(tryfirst=True)
24 # def pytest_runtest_protocol(self, item, nextitem):
25 # result = nextitem._result # Access the result object
26 #
27 # # Check if the test has failed
28 # if result and result.when == "call" and result.failed:
29 # test_info = {
30 # "name": item.name,
31 # "location": item.location,
32 # "parameters": item.keywords.get("fixturemanager").params
33 # }
34 # self.failed_tests.append(test_info)
35 # print(f"Failed test: {test_info}", file=sys.stderr)
37 def test_one_example_1(self):
38 """
39 Example one
40 :return: None
41 """
42 print(datetime.datetime.now(), file=sys.stderr)
43 self.shared_items.append((1, datetime.datetime.now()))
44 assert True
46 @pytest.mark.parametrize("param", [2, 3, 4])
47 def test_one_example_2(self, param):
48 """
49 Example two
50 :return: None
51 """
52 print(datetime.datetime.now(), file=sys.stderr)
53 self.shared_items.append((2, datetime.datetime.now()))
55 assert param % 2 == 0
57 @pytest.mark.run("last")
58 def test_one_last_example(self,):
59 """
60 Last Example
61 :return:
62 """
63 self.shared_items.append((3, datetime.datetime.now()))
64 assert True
66 @classmethod
67 def teardown_class(cls):
68 """
69 teardown any state that was previously setup with a call to setup_class.
70 """
71 print(f"Class shared items: {cls.failed_tests}", file=sys.stderr)
73 # def teardown_method(self, method):
74 # """
75 # teardown method, teardown any state that was previously setup with a setup_method call.
76 # :return: None
77 # """
78 # # get method results
79 # pdb.set_trace()