Skip to content

Commit

Permalink
uncomment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Jul 10, 2023
1 parent f596d3d commit 7107ce6
Showing 1 changed file with 93 additions and 92 deletions.
185 changes: 93 additions & 92 deletions pythonFiles/tests/pytestadapter/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,104 @@
from . import expected_discovery_test_output
from .helpers import TEST_DATA_PATH, runner

# def test_import_error(tmp_path):
# """Test pytest discovery on a file that has a pytest marker but does not import pytest.

# Copies the contents of a .txt file to a .py file in the temporary directory
# to then run pytest discovery on.

# The json should still be returned but the errors list should be present.

# Keyword arguments:
# tmp_path -- pytest fixture that creates a temporary directory.
# """
# # Saving some files as .txt to avoid that file displaying a syntax error for
# # the extension as a whole. Instead, rename it before running this test
# # in order to test the error handling.
# file_path = TEST_DATA_PATH / "error_pytest_import.txt"
# temp_dir = tmp_path / "temp_data"
# temp_dir.mkdir()
# p = temp_dir / "error_pytest_import.py"
# shutil.copyfile(file_path, p)
# actual_list: Optional[List[Dict[str, Any]]] = runner(
# ["--collect-only", os.fspath(p)]
# )
# assert actual_list
# for actual in actual_list:
# assert all(item in actual for item in ("status", "cwd", "error"))
# assert actual["status"] == "error"
# assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
# assert len(actual["error"]) == 2


# def test_syntax_error(tmp_path):
# """Test pytest discovery on a file that has a syntax error.

# Copies the contents of a .txt file to a .py file in the temporary directory
# to then run pytest discovery on.

# The json should still be returned but the errors list should be present.

# Keyword arguments:
# tmp_path -- pytest fixture that creates a temporary directory.
# """
# # Saving some files as .txt to avoid that file displaying a syntax error for
# # the extension as a whole. Instead, rename it before running this test
# # in order to test the error handling.
# file_path = TEST_DATA_PATH / "error_syntax_discovery.txt"
# temp_dir = tmp_path / "temp_data"
# temp_dir.mkdir()
# p = temp_dir / "error_syntax_discovery.py"
# shutil.copyfile(file_path, p)
# actual = runner(["--collect-only", os.fspath(p)])
# if actual:
# actual = actual[0]
# assert actual
# assert all(item in actual for item in ("status", "cwd", "error"))
# assert actual["status"] == "error"
# assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
# assert len(actual["error"]) == 2


# def test_parameterized_error_collect():
# """Tests pytest discovery on specific file that incorrectly uses parametrize.

# The json should still be returned but the errors list should be present.
# """
# file_path_str = "error_parametrize_discovery.py"
# actual = runner(["--collect-only", file_path_str])
# if actual:
# actual = actual[0]
# assert all(item in actual for item in ("status", "cwd", "error"))
# assert actual["status"] == "error"
# assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
# assert len(actual["error"]) == 2

def test_import_error(tmp_path):
"""Test pytest discovery on a file that has a pytest marker but does not import pytest.
Copies the contents of a .txt file to a .py file in the temporary directory
to then run pytest discovery on.
The json should still be returned but the errors list should be present.
Keyword arguments:
tmp_path -- pytest fixture that creates a temporary directory.
"""
# Saving some files as .txt to avoid that file displaying a syntax error for
# the extension as a whole. Instead, rename it before running this test
# in order to test the error handling.
file_path = TEST_DATA_PATH / "error_pytest_import.txt"
temp_dir = tmp_path / "temp_data"
temp_dir.mkdir()
p = temp_dir / "error_pytest_import.py"
shutil.copyfile(file_path, p)
actual_list: Optional[List[Dict[str, Any]]] = runner(
["--collect-only", os.fspath(p)]
)
assert actual_list
for actual in actual_list:
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2


def test_syntax_error(tmp_path):
"""Test pytest discovery on a file that has a syntax error.
Copies the contents of a .txt file to a .py file in the temporary directory
to then run pytest discovery on.
The json should still be returned but the errors list should be present.
Keyword arguments:
tmp_path -- pytest fixture that creates a temporary directory.
"""
# Saving some files as .txt to avoid that file displaying a syntax error for
# the extension as a whole. Instead, rename it before running this test
# in order to test the error handling.
file_path = TEST_DATA_PATH / "error_syntax_discovery.txt"
temp_dir = tmp_path / "temp_data"
temp_dir.mkdir()
p = temp_dir / "error_syntax_discovery.py"
shutil.copyfile(file_path, p)
actual = runner(["--collect-only", os.fspath(p)])
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2


def test_parameterized_error_collect():
"""Tests pytest discovery on specific file that incorrectly uses parametrize.
The json should still be returned but the errors list should be present.
"""
file_path_str = "error_parametrize_discovery.py"
actual = runner(["--collect-only", file_path_str])
if actual:
actual = actual[0]
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2


@pytest.mark.parametrize(
"file, expected_const",
[
# (
# "param_same_name",
# expected_discovery_test_output.param_same_name_expected_output,
# ),
# (
# "parametrize_tests.py",
# expected_discovery_test_output.parametrize_tests_expected_output,
# ),
# (
# "empty_discovery.py",
# expected_discovery_test_output.empty_discovery_pytest_expected_output,
# ),
# (
# "simple_pytest.py",
# expected_discovery_test_output.simple_discovery_pytest_expected_output,
# ),
# (
# "unittest_pytest_same_file.py",
# expected_discovery_test_output.unit_pytest_same_file_discovery_expected_output,
# ),
(
"param_same_name",
expected_discovery_test_output.param_same_name_expected_output,
),
(
"parametrize_tests.py",
expected_discovery_test_output.parametrize_tests_expected_output,
),
(
"empty_discovery.py",
expected_discovery_test_output.empty_discovery_pytest_expected_output,
),
(
"simple_pytest.py",
expected_discovery_test_output.simple_discovery_pytest_expected_output,
),
(
"unittest_pytest_same_file.py",
expected_discovery_test_output.unit_pytest_same_file_discovery_expected_output,
),
(
"unittest_folder",
expected_discovery_test_output.unittest_folder_discovery_expected_output,
Expand Down

0 comments on commit 7107ce6

Please sign in to comment.