question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v0.11.1: Unit test errors

See original GitHub issue

Running the unit tests on lark version 0.11.1 I get the following errors (using Python 3.8 and 3.9):

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestCykStandard)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestEarleyDynamic)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestEarleyStandard)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestLalrContextual)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestLalrCustom)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

======================================================================
ERROR: test_import_custom_sources (tests.test_parser.tests.test_parser.TestLalrStandard)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 1947, in test_import_custom_sources
    p = _Lark(grammar, import_paths=[custom_loader2])
  File "/<<PKGBUILDDIR>>/tests/test_parser.py", line 946, in _Lark
    return Lark(grammar, lexer=lexer_class_or_name, parser=PARSER, propagate_positions=True, **kwargs)
  File "/<<PKGBUILDDIR>>/lark/lark.py", line 300, in __init__
    self.grammar = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 1061, in load_grammar
    return GrammarLoader(global_keep_all_tokens).load_grammar(grammar, source, import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 978, in load_grammar
    g = self.import_grammar(grammar_path, base_path=base_path, import_paths=import_paths)
  File "/<<PKGBUILDDIR>>/lark/load_grammar.py", line 886, in import_grammar
    open(grammar_path, encoding='utf8')
FileNotFoundError: [Errno 2] No such file or directory: 'test_relative_import.lark'

----------------------------------------------------------------------
Ran 687 tests in 36.485s

FAILED (errors=6, skipped=68)

It seems the CI tests did not show a similar issue. Do you have any idea what is going wrong here?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
MegaIngcommented, Nov 22, 2020

With python -m tests it works. unittest does something else that somehow hurts file finding.

0reactions
MegaIngcommented, Nov 25, 2020

Ok, found the source of the ‘bug’. It is just that the tests weren’t able to deal with a situation where __main__ isn’t within tests. I will create a PR. lucky, the same commit that introduced this problem also contained an easy way to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unittest — Unit testing framework — Python 3.11.1 ...
Any exception, other than AssertionError or SkipTest , raised by this method will be considered an additional error rather than a test failure...
Read more >
Unit tests for testing error codes - Code Review Stack Exchange
Both unit tests pass and they both test the same thing. The production code uses the right error codes. System Under Test (SUT)...
Read more >
Unit Testing Guidelines - GeoSoft
Unit testing guidelines, recommendations and best practices. ... The trivial cases can contain errors too, often as a result of copy-paste operations:
Read more >
Jennings_SWEN647_P1_A4.doc - Project1 UnitTest 1.0 9/23 ...
Unittesting is a method when the developer reviews certain portions of source code looking for anypossible errors or bugs.The unit testing allows the ......
Read more >
wallaby v0.11.1 - HexDocs
Wallaby helps you test your web applications by simulating user interactions. ... If you're testing a Phoenix application with Ecto then you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found