From 7a5d952e9ec3ebe0de0d3df1debc6a83f6374005 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Fri, 7 Apr 2023 04:18:25 -0700 Subject: [PATCH] [Python 3.11.2 Upgrade] Updated Dockerfile and Requirements (#112) * Updated dockerfile and requirements to support python 3.11. Regenerated some golden files to match new 3.11 output. * Removed bin/bash entrypoint. * Added tomli versioning, just to be safe. * Adjusted runner to trim subtest noise and regenerated three test files. --- Dockerfile | 3 +-- pytest.ini | 4 ++++ requirements.txt | 7 ++++--- runner/__init__.py | 4 ++-- test/example-empty-file/results.json | 4 ++-- .../results.json | 6 ------ test/example-has-stdout-tasks-and-subtests/results.json | 8 ++++---- test/example-syntax-error/results.json | 4 ++-- 8 files changed, 19 insertions(+), 21 deletions(-) delete mode 100644 test/example-has-stdout-and-tasks-and-subtests/results.json diff --git a/Dockerfile b/Dockerfile index ad7fea0..fad5b25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10.6-slim +FROM python:3.11.2-slim COPY requirements.txt /requirements.txt @@ -15,4 +15,3 @@ COPY . /opt/test-runner WORKDIR /opt/test-runner ENTRYPOINT [ "/opt/test-runner/bin/run.sh" ] - diff --git a/pytest.ini b/pytest.ini index 54049bd..9ae8221 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,7 +1,11 @@ [pytest] +addopts = + --color=no norecursedirs = .git .github example* traceback-styles* cache_dir = /tmp/python_cache_dir markers = task: A concept exercise task. +console_output_style = + classic diff --git a/requirements.txt b/requirements.txt index d1c57bc..38486b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -pytest~=7.1.2 -pytest-subtests~=0.5.0 -tomli~=2.0.1 +black<=22.3.0 +pytest~=7.2.2 +pytest-subtests~=0.10.0 +tomli>=1.1.0; python_full_version < '3.11.2' diff --git a/runner/__init__.py b/runner/__init__.py index e05e1be..7ec9375 100644 --- a/runner/__init__.py +++ b/runner/__init__.py @@ -65,8 +65,8 @@ def pytest_runtest_logreport(self, report): # Update tests that have already failed with capstdout and return. if not state.is_passing(): - if report.capstdout.rstrip('FFFFFFFF '): - state.output = report.capstdout.rstrip('FFFFFFFF ') + if report.capstdout.rstrip('FFFFFFFF ').rstrip('uuuuu'): + state.output = report.capstdout.rstrip('FFFFFFFF ').rstrip('uuuuu') return # Record captured relevant stdout content for passed tests. diff --git a/test/example-empty-file/results.json b/test/example-empty-file/results.json index 466f19c..413ca2c 100644 --- a/test/example-empty-file/results.json +++ b/test/example-empty-file/results.json @@ -1,6 +1,6 @@ { "version": 3, "status": "error", - "message": " ImportError while importing test module './test/example-empty-file/example_empty_file_test.py'.\nHint: make sure your test modules/packages have valid Python names.\nTraceback:\n/usr/local/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\ntest/example-empty-file/example_empty_file_test.py:4: in \n from example_empty_file import hello\nE ImportError: cannot import name 'hello' from 'example_empty_file' (./test/example-empty-file/example_empty_file.py)", + "message": " ImportError while importing test module './test/example-empty-file/example_empty_file_test.py'.\nHint: make sure your test modules/packages have valid Python names.\nTraceback:\n/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\ntest/example-empty-file/example_empty_file_test.py:4: in \n from example_empty_file import hello\nE ImportError: cannot import name 'hello' from 'example_empty_file' (./test/example-empty-file/example_empty_file.py)", "tests": [] -} +} \ No newline at end of file diff --git a/test/example-has-stdout-and-tasks-and-subtests/results.json b/test/example-has-stdout-and-tasks-and-subtests/results.json deleted file mode 100644 index 393bcd2..0000000 --- a/test/example-has-stdout-and-tasks-and-subtests/results.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": 3, - "status": "error", - "message": "Unexpected ExitCode.USAGE_ERROR: check logs for details", - "tests": [] -} \ No newline at end of file diff --git a/test/example-has-stdout-tasks-and-subtests/results.json b/test/example-has-stdout-tasks-and-subtests/results.json index f6418e5..9f63c2e 100644 --- a/test/example-has-stdout-tasks-and-subtests/results.json +++ b/test/example-has-stdout-tasks-and-subtests/results.json @@ -8,7 +8,7 @@ "message": "One or more variations of this test failed. Details can be found under each [variant#].", "test_code": "input_data = [1, 2, 5, 10, 15, 23, 33, 39]\nresult_data = [(\"Hello, World!\", param) for param in input_data]\nnumber_of_variants = range(1, len(input_data) + 1)\n\nfor variant, param, result in zip(number_of_variants, input_data, result_data):\n with self.subTest(f\"variation #{variant}\", param=param, result=result):\n self.assertEqual(hello(param), result,\n msg=f'Expected: {result} but got something else instead.')", "task_id": 1, - "output": "Hello, World! 1\nHello, World! 2\nHello, World! 5\nHello, World! 10\nHello, World! 15\nHello, World! 23\nHello, World! 33\nHello, World! 39" + "output": "Hello, World! 1\nuHello, World! 2\nuHello, World! 5\nuHello, World! 10\nuHello, World! 15\nuHello, World! 23\nuHello, World! 33\nuHello, World! 39" }, { "name": "ExampleHasStdout > hello [variation #1] (param=1, result=('Hello, World!', 1))", @@ -72,7 +72,7 @@ "message": "One or more variations of this test failed. Details can be found under each [variant#].", "test_code": "input_data = ['frog', 'fish', 'coconut', 'pineapple', 'carrot', 'cucumber', 'grass', 'tree']\nresult_data = [(\"Hello, World!\", param) for param in input_data]\nnumber_of_variants = range(1, len(input_data) + 1)\n\nfor variant, param, result in zip(number_of_variants, input_data, result_data):\n with self.subTest(f\"variation #{variant}\", param=param, result=result):\n self.assertEqual(hello(param), result,\n msg=f'Expected: {result} but got something else instead.')", "task_id": 2, - "output": "Hello, World! frog\nHello, World! fish\nHello, World! coconut\nHello, World! pineapple\nHello, World! carrot\nHello, World! cucumber\nHello, World! grass\nHello, World! tree" + "output": "Hello, World! frog\nuHello, World! fish\nuHello, World! coconut\nuHello, World! pineapple\nuHello, World! carrot\nuHello, World! cucumber\nuHello, World! grass\nuHello, World! tree" }, { "name": "ExampleHasStdout > abc [variation #1] (param='frog', result=('Hello, World!', 'frog'))", @@ -144,7 +144,7 @@ "message": "One or more variations of this test failed. Details can be found under each [variant#].", "test_code": "input_data = ['frog', 'fish', 'coconut', 'pineapple', 'carrot', 'cucumber', 'grass', 'tree']\nresult_data = [(\"Hello, World!\", param) for param in input_data]\nnumber_of_variants = range(1, len(input_data) + 1)\n\nfor variant, param, result in zip(number_of_variants, input_data, result_data):\n with self.subTest(f\"variation #{variant}\", param=param, result=result):\n self.assertEqual(hello(param), result,\n msg=f'Expected: {result} but got something else instead.')", "task_id": 4, - "output": "Hello, World! frog\nHello, World! fish\nHello, World! coconut\nHello, World! pineapple\nHello, World! carrot\nHello, World! cucumber\nHello, World! grass\nHello, World! tree" + "output": "Hello, World! frog\nuHello, World! fish\nuHello, World! coconut\nuHello, World! pineapple\nuHello, World! carrot\nuHello, World! cucumber\nuHello, World! grass\nuHello, World! tree" }, { "name": "ExampleHasStdoutOther > dummy [variation #1] (param='frog', result=('Hello, World!', 'frog'))", @@ -208,7 +208,7 @@ "message": "One or more variations of this test failed. Details can be found under each [variant#].", "test_code": "input_data = [1, 2, 5, 10, 15, 23, 33, 39]\nresult_data = [(\"Hello, World!\", param) for param in input_data]\nnumber_of_variants = range(1, len(input_data) + 1)\n\nfor variant, param, result in zip(number_of_variants, input_data, result_data):\n with self.subTest(f\"variation #{variant}\", param=param, result=result):\n self.assertEqual(hello(param), result,\n msg=f'Expected: {result} but got something else instead.')", "task_id": 5, - "output": "Hello, World! 1\nHello, World! 2\nHello, World! 5\nHello, World! 10\nHello, World! 15\nHello, World! 23\nHello, World! 33\nHello, World! 39" + "output": "Hello, World! 1\nuHello, World! 2\nuHello, World! 5\nuHello, World! 10\nuHello, World! 15\nuHello, World! 23\nuHello, World! 33\nuHello, World! 39" }, { "name": "ExampleHasStdoutOther > hello [variation #1] (param=1, result=('Hello, World!', 1))", diff --git a/test/example-syntax-error/results.json b/test/example-syntax-error/results.json index 438dc71..9c4117c 100644 --- a/test/example-syntax-error/results.json +++ b/test/example-syntax-error/results.json @@ -1,6 +1,6 @@ { "version": 3, "status": "error", - "message": " /usr/local/lib/python3.10/site-packages/_pytest/python.py:608: in _importtestmodule\n mod = import_path(self.path, mode=importmode, root=self.config.rootpath)\n/usr/local/lib/python3.10/site-packages/_pytest/pathlib.py:533: in import_path\n importlib.import_module(module_name)\n/usr/local/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n:1050: in _gcd_import\n ???\n:1027: in _find_and_load\n ???\n:1006: in _find_and_load_unlocked\n ???\n:688: in _load_unlocked\n ???\n/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:168: in exec_module\n exec(co, module.__dict__)\ntest/example-syntax-error/example_syntax_error_test.py:4: in \n from example_syntax_error import hello\nE File \"./test/example-syntax-error/example_syntax_error.py\", line 3\nE def hello();\nE ^\nE SyntaxError: expected ':'", + "message": " /usr/local/lib/python3.11/site-packages/_pytest/python.py:618: in _importtestmodule\n mod = import_path(self.path, mode=importmode, root=self.config.rootpath)\n/usr/local/lib/python3.11/site-packages/_pytest/pathlib.py:533: in import_path\n importlib.import_module(module_name)\n/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n:1206: in _gcd_import\n ???\n:1178: in _find_and_load\n ???\n:1149: in _find_and_load_unlocked\n ???\n:690: in _load_unlocked\n ???\n/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:168: in exec_module\n exec(co, module.__dict__)\ntest/example-syntax-error/example_syntax_error_test.py:4: in \n from example_syntax_error import hello\nE File \"./test/example-syntax-error/example_syntax_error.py\", line 3\nE def hello();\nE ^\nE SyntaxError: expected ':'", "tests": [] -} +} \ No newline at end of file