From 7e6b34640272abeb29c91c8d951c2543293b01d0 Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Wed, 7 Jan 2026 17:07:34 +0100 Subject: [PATCH] [python] PCQA-1466 allow running Python 2 helpers tests (cherry picked from commit 1aeb8996b00683167c278ba924ab370059248c76) IJ-MR-187159 GitOrigin-RevId: 2fa35f5adbf8e10e82689f04eddf4a35e4ac8ecf --- python/helpersTests/requirements-py2.txt | 2 ++ python/helpersTests/run_python2_tests.py | 19 +++++++++++++++++++ .../tests/pycharm/test_jb_unittest_runner.py | 9 +++++++-- .../tests/pycharm/test_teamcity.py | 4 ++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 python/helpersTests/requirements-py2.txt create mode 100644 python/helpersTests/run_python2_tests.py diff --git a/python/helpersTests/requirements-py2.txt b/python/helpersTests/requirements-py2.txt new file mode 100644 index 000000000000..ff97e12d4cd3 --- /dev/null +++ b/python/helpersTests/requirements-py2.txt @@ -0,0 +1,2 @@ +behave==1.3.3 +pytest==4.6.11 \ No newline at end of file diff --git a/python/helpersTests/run_python2_tests.py b/python/helpersTests/run_python2_tests.py new file mode 100644 index 000000000000..5b7ab5ad4f7f --- /dev/null +++ b/python/helpersTests/run_python2_tests.py @@ -0,0 +1,19 @@ +import os +import sys + +import pytest + + +current_dir = os.path.dirname(os.path.abspath(__file__)) +python_plugin_dir = os.path.abspath(os.path.join(current_dir, '..')) + +helpers_dir = os.path.join(python_plugin_dir, "helpers") +pycharm_dir = os.path.join(helpers_dir, "pycharm") +py3only_dir = os.path.join(helpers_dir, "py3only") + +sys.path.insert(0, helpers_dir) +sys.path.insert(0, pycharm_dir) +sys.path.insert(0, py3only_dir) + +exit_code = pytest.main(["--junit-xml=.tox/reports/junit-py27.xml", "tests"]) +sys.exit(exit_code) diff --git a/python/helpersTests/tests/pycharm/test_jb_unittest_runner.py b/python/helpersTests/tests/pycharm/test_jb_unittest_runner.py index 8c34a3632745..892fd3e0a203 100644 --- a/python/helpersTests/tests/pycharm/test_jb_unittest_runner.py +++ b/python/helpersTests/tests/pycharm/test_jb_unittest_runner.py @@ -5,6 +5,7 @@ import pytest from pycharm._jb_unittest_runner import build_unittest_args +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_path_doesnt_exist(): pattern = r"No such file or directory: 'test_foo.py'" with pytest.raises(OSError, match=pattern): @@ -12,6 +13,7 @@ def test_path_doesnt_exist(): +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_targets(): assert build_unittest_args( path=None, @@ -26,6 +28,7 @@ def test_targets(): ] +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_quiet_discover(tmp_path): assert build_unittest_args( path=str(tmp_path), @@ -44,6 +47,7 @@ def test_quiet_discover(tmp_path): ] +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_verbose_discover(tmp_path): assert build_unittest_args( path=str(tmp_path), @@ -70,7 +74,6 @@ def test_python2(tmp_path): additional_args=[], verbose=True, project_dir="/project_dir", - python_version=(2, 7), ) == [ "python -m unittest", "discover", @@ -93,7 +96,6 @@ def test_python2_and_path_is_file(tmp_path): additional_args=[], verbose=True, project_dir="/project_dir", - python_version=(2, 7), ) == [ "python -m unittest", "discover", @@ -125,6 +127,7 @@ def test_python3_and_path_is_file(tmp_path): ] +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_user_args(): assert build_unittest_args( path=None, @@ -141,6 +144,7 @@ def test_user_args(): ] +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_user_overrides_verbosity(): assert build_unittest_args( path=None, @@ -156,6 +160,7 @@ def test_user_overrides_verbosity(): ] +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_rerun_failed_tests(): assert build_unittest_args( path=None, diff --git a/python/helpersTests/tests/pycharm/test_teamcity.py b/python/helpersTests/tests/pycharm/test_teamcity.py index 81c1b3d76cd3..77a2638444f4 100644 --- a/python/helpersTests/tests/pycharm/test_teamcity.py +++ b/python/helpersTests/tests/pycharm/test_teamcity.py @@ -1,9 +1,12 @@ +import sys + import pytest pytest_plugins = "pytester" # PY-84850 +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_teamcity_plugin_with_xdist(pytester): pytester.makepyfile(""" def test_example_1(): @@ -25,6 +28,7 @@ def test_teamcity_plugin_with_xdist(pytester): # PY-84850 +@pytest.mark.skipif(sys.version_info < (3, 0), reason="Python 3 is required") def test_teamcity_plugin_without_xdist(pytester): pytester.makepyfile(""" def test_basic():