2626 chdir ,
2727 generate ,
2828)
29- from datamodel_code_generator .__main__ import Exit , main
29+ from datamodel_code_generator .__main__ import Exit
3030from datamodel_code_generator .format import is_supported_in_black
3131from datamodel_code_generator .model import base as model_base
3232from tests .conftest import assert_directory_content , freeze_time , validate_generated_code
5353FixtureRequest = pytest .FixtureRequest
5454
5555
56+ @pytest .mark .allow_direct_assert
5657def assert_run_main_with_args_error (args : list [str ], capsys : pytest .CaptureFixture [str ], expected_error : str ) -> None :
5758 """Assert that running the CLI exits with code 2 and emits the expected error."""
5859 with pytest .raises (SystemExit ) as exc_info :
@@ -212,6 +213,7 @@ def test_main_keep_model_order_field_references(output_file: Path) -> None:
212213 )
213214
214215
216+ @pytest .mark .allow_direct_assert
215217@pytest .mark .parametrize (
216218 ("target_python_version" , "keep_model_order" , "disable_future_imports" ),
217219 [
@@ -452,6 +454,7 @@ def test_main_jsonschema_multiple_files(output_dir: Path) -> None:
452454 )
453455
454456
457+ @pytest .mark .allow_direct_assert
455458@pytest .mark .benchmark
456459def test_main_jsonschema_no_empty_collapsed_external_model (tmp_path : Path ) -> None :
457460 """Test no empty files with collapsed external models."""
@@ -773,28 +776,32 @@ def test_main_class_name_suffix_with_class_name(output_file: Path) -> None:
773776
774777def test_main_class_name_prefix_invalid (output_file : Path ) -> None :
775778 """Test that invalid --class-name-prefix is rejected."""
776- return_code : Exit = main ([
777- "--input" ,
778- str (JSON_SCHEMA_DATA_PATH / "class_name_affix.json" ),
779- "--output" ,
780- str (output_file ),
781- "--class-name-prefix" ,
782- "123Invalid" ,
783- ])
784- assert return_code == Exit .ERROR
779+ run_main_with_args (
780+ [
781+ "--input" ,
782+ str (JSON_SCHEMA_DATA_PATH / "class_name_affix.json" ),
783+ "--output" ,
784+ str (output_file ),
785+ "--class-name-prefix" ,
786+ "123Invalid" ,
787+ ],
788+ expected_exit = Exit .ERROR ,
789+ )
785790
786791
787792def test_main_class_name_suffix_invalid (output_file : Path ) -> None :
788793 """Test that invalid --class-name-suffix is rejected."""
789- return_code : Exit = main ([
790- "--input" ,
791- str (JSON_SCHEMA_DATA_PATH / "class_name_affix.json" ),
792- "--output" ,
793- str (output_file ),
794- "--class-name-suffix" ,
795- "Schema!" ,
796- ])
797- assert return_code == Exit .ERROR
794+ run_main_with_args (
795+ [
796+ "--input" ,
797+ str (JSON_SCHEMA_DATA_PATH / "class_name_affix.json" ),
798+ "--output" ,
799+ str (output_file ),
800+ "--class-name-suffix" ,
801+ "Schema!" ,
802+ ],
803+ expected_exit = Exit .ERROR ,
804+ )
798805
799806
800807def test_main_jsonschema_reserved_field_names (output_file : Path ) -> None :
@@ -1002,6 +1009,7 @@ def test_main_root_id_jsonschema_with_absolute_local_file(output_file: Path) ->
10021009 )
10031010
10041011
1012+ @pytest .mark .allow_direct_assert
10051013def test_main_url_with_relative_root_id_resolves_relative_refs (mocker : MockerFixture , tmp_path : Path ) -> None :
10061014 """Test --url input keeps resolving relative refs remotely when root $id is path-only."""
10071015 main_response = mocker .Mock ()
@@ -1909,6 +1917,7 @@ def test_main_generate_relative_input_path(output_file: Path) -> None:
19091917 )
19101918
19111919
1920+ @pytest .mark .allow_direct_assert
19121921def test_main_generate_external_absolute_input_path (tmp_path : Path ) -> None :
19131922 """Test helper keeps absolute input paths that are outside the repository root."""
19141923 with tempfile .TemporaryDirectory () as temp_dir :
@@ -2149,6 +2158,7 @@ def test_main_generate_pydantic_v2_dataclass_enum(output_file: Path) -> None:
21492158 )
21502159
21512160
2161+ @pytest .mark .allow_direct_assert
21522162@pytest .mark .parametrize (
21532163 ("input_file" , "expected_file" ),
21542164 [
@@ -2174,6 +2184,7 @@ def test_main_generate_pydantic_v2_model_default_dict(input_file: str, expected_
21742184 assert_file_content (output_file , expected_file )
21752185
21762186
2187+ @pytest .mark .allow_direct_assert
21772188def test_main_generate_from_directory (tmp_path : Path ) -> None :
21782189 """Test generation from directory input."""
21792190 input_ = (JSON_SCHEMA_DATA_PATH / "external_files_in_directory" ).relative_to (Path .cwd ())
@@ -2240,6 +2251,7 @@ def keep_underscores(name: str) -> str:
22402251 )
22412252
22422253
2254+ @pytest .mark .allow_direct_assert
22432255def test_main_http_jsonschema (mocker : MockerFixture , output_file : Path ) -> None :
22442256 """Test HTTP JSON Schema fetching."""
22452257 external_directory = JSON_SCHEMA_DATA_PATH / "external_files_in_directory"
@@ -2351,6 +2363,7 @@ def get_mock_response(url: str, **_: object) -> mocker.Mock:
23512363 assert httpx_get_mock .call_count == 8
23522364
23532365
2366+ @pytest .mark .allow_direct_assert
23542367@pytest .mark .parametrize (
23552368 (
23562369 "headers_arguments" ,
@@ -3304,6 +3317,7 @@ def test_long_description_wrap_string_literal(output_file: Path) -> None:
33043317 )
33053318
33063319
3320+ @pytest .mark .allow_direct_assert
33073321def test_version (capsys : pytest .CaptureFixture ) -> None :
33083322 """Test version output."""
33093323 with pytest .raises (SystemExit ) as e :
@@ -9006,6 +9020,7 @@ def test_field_validators_wrap_mode(output_file: Path, tmp_path: Path) -> None:
90069020 )
90079021
90089022
9023+ @pytest .mark .allow_direct_assert
90099024def test_field_validators_with_no_field_skipped (output_file : Path , tmp_path : Path ) -> None :
90109025 """Test that validators without fields are skipped gracefully."""
90119026 config_file = tmp_path / "no_field_validators_config.json"
@@ -9070,6 +9085,7 @@ def test_field_validators_plain_mode(output_file: Path, tmp_path: Path) -> None:
90709085 )
90719086
90729087
9088+ @pytest .mark .allow_direct_assert
90739089def test_field_validators_all_skipped (output_file : Path , tmp_path : Path ) -> None :
90749090 """Test that when all validators have no fields, output has no validators."""
90759091 config_file = tmp_path / "all_skipped_config.json"
@@ -9267,6 +9283,7 @@ def test_main_circular_ref_external_relative_keywords(output_file: Path) -> None
92679283 )
92689284
92699285
9286+ @pytest .mark .allow_direct_assert
92709287@pytest .mark .benchmark
92719288def test_main_circular_ref_external_url_keywords (mocker : MockerFixture , output_file : Path ) -> None :
92729289 """Test circular external refs with relative paths and schema keywords via URL input."""
0 commit comments