gleb-sevruk / pycrunch-engine

NCrunch inspired tool for continuous testing Python
https://pycrunch.com
Other
57 stars 8 forks source link

Add `ast.AsyncFunctionDef` to correctly recognize async test methods. #100

Closed accoleon closed 9 months ago

accoleon commented 9 months ago

Resolves #62

gleb-sevruk commented 9 months ago

Great addition, I will do minimal testing and merge it tomorrow.

gleb-sevruk commented 9 months ago

Can you actually run async test? I got

        if events._get_running_loop() is not None:
>           raise RuntimeError(
                'Cannot run the event loop while another loop is running')
E           RuntimeError: Cannot run the event loop while another loop is running

And need to dig deeper

Side note -> tests are now discovered, and thats excellent

accoleon commented 9 months ago

I did - however the actual running of the async tests required nest_asyncio as described in https://github.com/gleb-sevruk/pycrunch-engine/issues/52#issuecomment-908045411 - I didn't look further into the async system unfortunately. That will come next time!

gleb-sevruk commented 9 months ago

I got it working via next-asyncio in pycrunch/multiprocess_child_main.py

import nest_asyncio
nest_asyncio.apply()

preparing a fix

gleb-sevruk commented 9 months ago

Seems up and running now: https://github.com/gleb-sevruk/pycrunch-engine/pull/101

accoleon commented 9 months ago

🙌

gleb-sevruk commented 9 months ago

Thanks a lot; Version 1.6.1 Is published; Let me know about the experience.

https://pypi.org/project/pycrunch-engine/1.6.1/

gleb-sevruk commented 9 months ago

You will need to enable plugins in .pycrunch-config.yaml for this to work

engine:
  load-pytest-plugins: true
accoleon commented 9 months ago

Yep! Just tested 1.6.1 and works great. Pretty awesome, I loved ncrunch when I was working in .NET and have been looking for something for Python ever since!

vegaroy13 commented 9 months ago

Oh Thank You. Just update to back front last updates (1.6.1) and works over python 3.10. Previous versions of python will fail due to syntax updated code not supported.

gleb-sevruk commented 9 months ago

@vegaroy13 Oh I see what you mean

[98109] 2023-10-17 14:42:45,834 - pycrunch.discovery.ast_discovery - ERROR -  parse test_one.py failed with exception: unsupported operand type(s) for |: 'type' and 'type'
Traceback (most recent call last):
  File "/Users/gleb/venv/pycrunch_161_39_testing/lib/python3.9/site-packages/pycrunch/discovery/ast_discovery.py", line 68, in find_tests_in_folder
    tests_found = self.load_tests_from_ast_representation(ast_tree)
  File "/Users/gleb/venv/pycrunch_161_39_testing/lib/python3.9/site-packages/pycrunch/discovery/ast_discovery.py", line 98, in load_tests_from_ast_representation
    def process_function_def(func: ast.FunctionDef | ast.AsyncFunctionDef) -> List[str]:
TypeError: unsupported operand type(s) for |: 'type' and 'type'
[98109] 2023-10-17 14:42:45,835 - pycrunch.discovery.ast_discovery - INFO -  Time spent parsing AST : 0.0 seconds

I will do another version with typing.Union to make sure it can still work on 3.9

gleb-sevruk commented 9 months ago

Version 1.6.2 uploaded to pip; should resolve compatibility issues with Python 3.9