1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #24250 from dkurt:ts_fixture_constructor_skip_2

Skip test on SkipTestException at fixture's constructor (version 2) #24250

### Pull Request Readiness Checklist

Another version of https://github.com/opencv/opencv/pull/24186 (reverted by https://github.com/opencv/opencv/pull/24223). Current implementation cannot handle skip exception at `static void SetUpTestCase` but works on `virtual void SetUp`.

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev
2023-09-18 10:23:24 +03:00
committed by GitHub
parent 687fc11626
commit 6bc369fc56
3 changed files with 45 additions and 4 deletions
+12
View File
@@ -917,5 +917,17 @@ REGISTER_TYPED_TEST_CASE_P(Rect_Test, Overflows);
typedef ::testing::Types<int, float, double> RectTypes;
INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Rect_Test, RectTypes);
// Expected that SkipTestException thrown in the constructor should skip test but not fail
struct TestFixtureSkip: public ::testing::Test {
TestFixtureSkip(bool throwEx = true) {
if (throwEx) {
throw SkipTestException("Skip test at constructor");
}
}
};
TEST_F(TestFixtureSkip, NoBodyRun) {
FAIL() << "Unreachable code called";
}
}} // namespace
+2
View File
@@ -36,6 +36,8 @@ class NewOpenCVTests(unittest.TestCase):
return candidate
if required:
self.fail('File ' + filename + ' not found')
else:
self.skipTest('File ' + filename + ' not found')
return None
+31 -4
View File
@@ -47,6 +47,15 @@ bool checkBigDataTests();
} \
} \
struct SkipThisTest : public ::testing::Test {
SkipThisTest(const std::string& msg_) : msg(msg_) {}
virtual void TestBody() CV_OVERRIDE {
printf("[ SKIP ] %s\n", msg.c_str());
}
std::string msg;
};
#undef TEST
#define TEST_(test_case_name, test_name, parent_class, bodyMethodName, BODY_ATTR, BODY_IMPL) \
@@ -60,6 +69,16 @@ bool checkBigDataTests();
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
};\
class test_case_name##test_name##_factory : public ::testing::internal::TestFactoryBase { \
public:\
virtual ::testing::Test* CreateTest() { \
try { \
return new GTEST_TEST_CLASS_NAME_(test_case_name, test_name); \
} catch (const cvtest::details::SkipTestExceptionBase& e) { \
return new SkipThisTest(e.what()); \
} \
} \
};\
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
::test_info_ =\
@@ -69,8 +88,7 @@ bool checkBigDataTests();
(::testing::internal::GetTestTypeId()), \
parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
new test_case_name##test_name##_factory);\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() BODY_IMPL( #test_case_name "_" #test_name ) \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::bodyMethodName()
@@ -113,6 +131,16 @@ bool checkBigDataTests();
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_fixture, test_name));\
};\
class test_fixture##test_name##_factory : public ::testing::internal::TestFactoryBase { \
public:\
virtual ::testing::Test* CreateTest() { \
try { \
return new GTEST_TEST_CLASS_NAME_(test_fixture, test_name); \
} catch (const cvtest::details::SkipTestExceptionBase& e) { \
return new SkipThisTest(e.what()); \
} \
} \
};\
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_fixture, test_name)\
::test_info_ =\
@@ -122,8 +150,7 @@ bool checkBigDataTests();
(::testing::internal::GetTypeId<test_fixture>()), \
test_fixture::SetUpTestCase, \
test_fixture::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<\
GTEST_TEST_CLASS_NAME_(test_fixture, test_name)>);\
new test_fixture##test_name##_factory);\
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() CV__TEST_BODY_IMPL( #test_fixture "_" #test_name ) \
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::Body()