Skip to content

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

Merged
asmorkalov merged 13 commits intoopencv:4.xfrom
dkurt:ts_fixture_constructor_skip_2
Sep 18, 2023
Merged

Skip test on SkipTestException at fixture's constructor (version 2)#24250
asmorkalov merged 13 commits intoopencv:4.xfrom
dkurt:ts_fixture_constructor_skip_2

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented Sep 9, 2023

Pull Request Readiness Checklist

Another version of #24186 (reverted by #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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov asmorkalov added this to the 4.9.0 milestone Sep 13, 2023
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov
Copy link
Copy Markdown
Contributor

@opencv-alalek Do you agree to merge the patch?

{
if (std::find(skipped_tests.begin(), skipped_tests.end(),
::testing::UnitTest::GetInstance()->current_test_info()) != skipped_tests.end()) {
throw details::SkipTestExceptionBase(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkurt Why do we need this?
What is the usecase? (usage example of the problem)

Copy link
Copy Markdown
Member Author

@dkurt dkurt Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does findDataFile() call checkTestTags()?

On failure findDataFile() throws CV_Error() or SkipTestException exception.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, findDataFile throws an exception but it is ignored on 4.x:

TEST(TestFixture2, should_skip) {
    findDataFile("not_a_file.png", false);
}

struct TestFixture : public ::testing::Test {
    TestFixture() {
        printf("enter constructor\n");
        findDataFile("not_a_file.png", false);
        printf("finish constructor\n");
    }
};

TEST_F(TestFixture, Body) {
    printf("enter test body\n");
}
$ ./bin/opencv_test_core --gtest_filter=TestFixture*

Note: Google Test filter = TestFixture*
[==========] Running 2 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 1 test from TestFixture2
[ RUN      ] TestFixture2.should_skip
[     SKIP ] OpenCV tests: Can't find data file: not_a_file.png
[       OK ] TestFixture2.should_skip (0 ms)
[----------] 1 test from TestFixture2 (0 ms total)

[----------] 1 test from TestFixture
[ RUN      ] TestFixture.Body
enter constructor
unknown file: Failure
C++ exception with description "OpenCV tests: Can't find data file: not_a_file.png" thrown in the test fixture's constructor.
[  FAILED  ] TestFixture.Body (1 ms)
[----------] 1 test from TestFixture (1 ms total)

[----------] Global test environment tear-down
[ SKIPSTAT ] 2 tests skipped
[ SKIPSTAT ] TAG='skip_other' skip 2 tests
[==========] 2 tests from 2 test cases ran. (2 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestFixture.Body

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR checkTestTags is called for a dummy test object which returns by a factory if test fixture thrown SkipTestException.

Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkTestTags is called for a dummy test object

Why not just throw SkipTestException instead?


Make sense to rename DummyTest to SkipThisTest.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were able to avoid this check for the case with exception at constructor. Exception at SetUp will probably require some isSkipped flag in GTEST_TEST_CLASS_NAME_ (will do by a next commit).

@dkurt dkurt force-pushed the ts_fixture_constructor_skip_2 branch from b15feee to 79bdb4d Compare September 15, 2023 14:19
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done 👍 Thank you!

@asmorkalov asmorkalov merged commit 6bc369f into opencv:4.x Sep 18, 2023
@dkurt dkurt deleted the ts_fixture_constructor_skip_2 branch September 18, 2023 07:47
@asmorkalov asmorkalov mentioned this pull request Sep 28, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Skip test on SkipTestException at fixture's constructor (version 2) opencv#24250

### Pull Request Readiness Checklist

Another version of opencv#24186 (reverted by opencv#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
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Skip test on SkipTestException at fixture's constructor (version 2) opencv#24250

### Pull Request Readiness Checklist

Another version of opencv#24186 (reverted by opencv#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants