diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-04-26 13:38:24 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-04-26 13:38:24 +0300 |
commit | d5542c891803641fb11f2edf0d71e6004a5e9c38 (patch) | |
tree | 592fd52d5412775f103fab3beb0083c08de7837f | |
parent | e42e29335e2001970f95535e7557d5c27519f29f (diff) | |
download | ydb-d5542c891803641fb11f2edf0d71e6004a5e9c38.tar.gz |
intermediate changes
ref:ba3b994bce107b5d5ed74af8bebe6df02576505a
-rw-r--r-- | build/rules/autocheck.blacklist | 1 | ||||
-rw-r--r-- | library/cpp/testing/unittest/pytests/test_subject/tests.cpp | 34 | ||||
-rw-r--r-- | library/cpp/testing/unittest/pytests/test_tear_down.py | 17 | ||||
-rw-r--r-- | library/cpp/testing/unittest/registar.h | 16 |
4 files changed, 66 insertions, 2 deletions
diff --git a/build/rules/autocheck.blacklist b/build/rules/autocheck.blacklist index 8ab5d41eea..e4739fab32 100644 --- a/build/rules/autocheck.blacklist +++ b/build/rules/autocheck.blacklist @@ -1409,3 +1409,4 @@ bunker/bunker-queue bunker/database haas/factory-packages adv/pcode/mobileadssdk/android/library +classifieds/realty/feedloader diff --git a/library/cpp/testing/unittest/pytests/test_subject/tests.cpp b/library/cpp/testing/unittest/pytests/test_subject/tests.cpp new file mode 100644 index 0000000000..677e5130ed --- /dev/null +++ b/library/cpp/testing/unittest/pytests/test_subject/tests.cpp @@ -0,0 +1,34 @@ +#include <library/cpp/testing/unittest/registar.h> + +namespace NSubjectTests { + class TAlwaysTearDownFixture : public NUnitTest::TBaseFixture { + public: + void TearDown(NUnitTest::TTestContext&) override { + Cerr << Name_ << ": TearDown is ran" << Endl; + } + }; + + class TAlwaysTearDownSetUpThrowsFixture : public NUnitTest::TBaseFixture { + public: + void SetUp(NUnitTest::TTestContext&) override { + ythrow yexception() << "hope this won't skip teardown"; + } + + void TearDown(NUnitTest::TTestContext&) override { + Cerr << Name_ << ": TearDown is ran" << Endl; + } + }; + + Y_UNIT_TEST_SUITE(TestsAlwaysTearDown) { + Y_UNIT_TEST_F(TestFail, TAlwaysTearDownFixture) { + UNIT_ASSERT(false); + } + + Y_UNIT_TEST_F(TestThrow, TAlwaysTearDownFixture) { + ythrow yexception() << "hope this won't skip teardown"; + } + + Y_UNIT_TEST_F(TestSetUpThrows, TAlwaysTearDownSetUpThrowsFixture) { + } + } +} diff --git a/library/cpp/testing/unittest/pytests/test_tear_down.py b/library/cpp/testing/unittest/pytests/test_tear_down.py new file mode 100644 index 0000000000..5aec40198d --- /dev/null +++ b/library/cpp/testing/unittest/pytests/test_tear_down.py @@ -0,0 +1,17 @@ +import yatest.common as ya_common + + +def test_sanity(): + test_path = ya_common.binary_path("library/cpp/testing/unittest/pytests/test_subject/library-cpp-testing-unittest-pytests-test_subject") + + tests = ya_common.execute([test_path, '-A']).std_out \ + .decode().strip().split('\n') + + assert tests + + for test in tests: + name = test.split('::')[1] + res = ya_common.execute([test_path, test], check_exit_code=False) + assert res.exit_code != 0 + lines = res.std_err.decode().split('\n') + assert f"{name}: TearDown is ran" in lines diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 4d5352e548..ac2bf5d514 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -7,6 +7,7 @@ #include <util/generic/intrlist.h> #include <util/generic/map.h> #include <util/generic/ptr.h> +#include <util/generic/scope.h> #include <util/generic/set.h> #include <util/generic/typetraits.h> #include <util/generic/vector.h> @@ -962,10 +963,21 @@ public: \ this->BeforeTest(i->Name_); \ { \ TCleanUp cleaner(this); \ - auto testCase = [&i, &context] { \ + auto testCase = [this, &i, &context] { \ + Y_DEFER { \ + try { \ + i->TearDown(context); \ + } catch (const ::NUnitTest::TAssertException&) { \ + } catch (const yexception& e) { \ + CATCH_REACTION_BT(i->Name_, e, &context); \ + } catch (const std::exception& e) { \ + CATCH_REACTION(i->Name_, e, &context); \ + } catch (...) { \ + this->AddError("non-std exception!", &context); \ + } \ + }; \ i->SetUp(context); \ i->Execute_(context); \ - i->TearDown(context); \ }; \ this->T::Run(testCase, StaticName(), i->Name_, i->ForceFork_); \ } \ |