From 3bdc81e10021db65be532668efeb552f41a0cb55 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 1 Aug 2019 15:45:22 +0300 Subject: [PATCH] Extract @python2_only/@python3_only helper test decorators GitOrigin-RevId: 7974c3d8abd28c5d7b576586ae76175016a9a9a8 --- python/helpers/tests/generator3_tests/__init__.py | 5 +++++ .../helpers/tests/generator3_tests/test_generation.py | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/python/helpers/tests/generator3_tests/__init__.py b/python/helpers/tests/generator3_tests/__init__.py index faf0a6fc5e9d..e8c0d47c4221 100644 --- a/python/helpers/tests/generator3_tests/__init__.py +++ b/python/helpers/tests/generator3_tests/__init__.py @@ -7,12 +7,17 @@ import unittest from contextlib import contextmanager from io import open +import six + from pycharm_generator_utils.constants import ENV_TEST_MODE_FLAG _test_dir = os.path.dirname(__file__) _test_data_root_dir = os.path.join(_test_dir, 'data') _override_test_data = False +python3_only = unittest.skipUnless(six.PY3, 'Python 3 only test') +python2_only = unittest.skipUnless(six.PY2, 'Python 2 only test') + class GeneratorTestCase(unittest.TestCase): longMessage = True diff --git a/python/helpers/tests/generator3_tests/test_generation.py b/python/helpers/tests/generator3_tests/test_generation.py index 87c5835bcf1e..09b23359663e 100644 --- a/python/helpers/tests/generator3_tests/test_generation.py +++ b/python/helpers/tests/generator3_tests/test_generation.py @@ -5,9 +5,8 @@ import textwrap import unittest import generator3 -import six from generator3 import GenerationStatus -from generator3_tests import GeneratorTestCase +from generator3_tests import GeneratorTestCase, python3_only, python2_only from pycharm_generator_utils.constants import ( CACHE_DIR_NAME, ENV_REQUIRED_GEN_VERSION_FILE, @@ -251,11 +250,11 @@ class SkeletonCachingTest(GeneratorTestCase): def test_cache_skeleton_regenerated_when_sdk_skeleton_generation_failed_for_modified_binary(self): self.check_generator_output('mod', mod_path='mod.py', gen_version='0.1', custom_required_gen=True) - @unittest.skipUnless(six.PY3, "Python 3 version of the test") + @python3_only def test_inaccessible_class_attribute_py3(self): self.check_generator_output('mod', mod_path='mod.py', success=False) - @unittest.skipUnless(six.PY2, "Python 2 version of the test") + @python2_only def test_inaccessible_class_attribute_py2(self): self.check_generator_output('mod', mod_path='mod.py', success=False) @@ -304,14 +303,14 @@ class SkeletonCachingTest(GeneratorTestCase): self.assertTrue(os.path.exists(os.path.join(self.temp_skeletons_dir, 'pyexpat', 'model.py'))) self.assertTrue(os.path.exists(os.path.join(self.temp_skeletons_dir, 'pyexpat', 'errors.py'))) - @unittest.skipUnless(six.PY3, 'Python 3 only test') + @python3_only def test_introspecting_submodule_modifies_sys_modules(self): self.check_generator_output('mod', 'mod.py') # PY-37241 # Python 2 version of the skeleton differs significantly # TODO investigate why - @unittest.skipUnless(six.PY3, 'Python 3 only test') + @python3_only def test_non_string_dunder_module(self): self.check_generator_output('mod', 'mod.py')