rstcheck / rstcheck-core

Core library behind rstcheck.
http://rstcheck-core.rtfd.io/
MIT License
4 stars 8 forks source link

[Bug]: test `TestCodeBlockChecker.test_check_yaml_returns_error_on_bad_code_block` fails #84

Closed natsukium closed 10 months ago

natsukium commented 11 months ago

To Dos

Example Code (python)

# these are shell commands

git clone https://github.com/rstcheck/rstcheck-core
cd rstcheck-core
git checkout v1.2.0
pip install .[testing]
pytest tests/checker_test.py

Relevant log output

――――――――――――――――――――――――――――――――――――――――――――――――― TestCodeBlockChecker.test_check_yaml_returns_error_on_bad_code_block ――――――――――――――――――――――――――――――――――――――――――――――――――

        @staticmethod
        def test_check_yaml_returns_error_on_bad_code_block() -> None:
            """Test ``check_json`` returns error on bad code block."""
            source = """
    spam: ham
      eggs: ham
    """
            cb_checker = checker.CodeBlockChecker("<string>")

            result = list(cb_checker.check_yaml(source))

>           assert len(result) == 1
E           assert 0 == 1
E            +  where 0 = len([])

cb_checker = <rstcheck_core.checker.CodeBlockChecker object at 0x7f5eba098e10>
result     = []
source     = '\nspam: ham\n  eggs: ham\n'

tests/checker_test.py:836: AssertionError

Description

I am not sure. Maybe this test expects an error but it does not handle the error.

Operating System

Linux

Operating System Details

No response

Python Version

3.11.5

rstcheck Version

1.2.0

Additional Context

No response

Cielquan commented 10 months ago

Sorry for the late response. The issue flew under my radar.

The tested function is here. It is tried to parse the yaml source. All yaml errors are catched and converted into LintErrors which are no exceptions but just a custom type. All the LintErrors are printed by rstcheck at the end. So there are no errors to handle in the test.

The CI run (ubuntu py 3.11) just before the 1.2 release was green in all 6 cases. Will need to test on my local maschine, if I can reproduce your issue.

EDIT: fix GHA error in logs (was my browser)

Cielquan commented 10 months ago

The issue is that the test runs even when pyyaml is not installed. Therefore it fails. I added a skip condition in the linked PR so this issue should be fixed.

Because the base test tox env always had pyyaml installed this issue was not discovered in CI. In the PR I also remove yaml from the base test env and added a new one for testing with pyyaml.

natsukium commented 10 months ago

Thank you!