pytest-tui icon indicating copy to clipboard operation
pytest-tui copied to clipboard

Address use of `tui` and `tuih` when cwd gets changed by the user's setup

Open jeffwright13 opened this issue 3 years ago • 2 comments

Another weird use case where a user customizes their setup such that the cwd is changed after launch. This places the results dir 'ptt_files' elsewhere, resulting in the tui and tuih console scripts not being able to find their .pickle and .ansi files.

$ tui
Traceback (most recent call last):
  File "/Users/jwr003/repos/gems-qa-auto/venv/bin/tui", line 8, in <module>
    sys.exit(tui_run())
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/__main__.py", line 289, in tui_run
    tui1()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/tui1.py", line 234, in main
    app.run()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/app.py", line 206, in run
    asyncio.run(run_app())
  File "/Users/jwr003/.pyenv/versions/3.9.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/jwr003/.pyenv/versions/3.9.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/app.py", line 204, in run_app
    await app.process_messages()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/app.py", line 291, in process_messages
    await self.dispatch_message(load_event)
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/message_pump.py", line 232, in dispatch_message
    await self.on_event(message)
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/app.py", line 434, in on_event
    await super().on_event(event)
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/message_pump.py", line 254, in on_event
    await invoke(method, event)
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/textual/_callback.py", line 29, in invoke
    result = await result
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/tui1.py", line 115, in on_load
    self.summary_results = self.results.tui_sections.lastline.content.replace(
AttributeError: 'NoneType' object has no attribute 'lastline'
/Users/jwr003/.pyenv/versions/3.9.9/lib/python3.9/asyncio/base_events.py:681: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
(gems-qa-auto)
~/repos/gems-qa-auto on  QAF-389! ⌚ 1:13:00
$ tuih
Traceback (most recent call last):
  File "/Users/jwr003/repos/gems-qa-auto/venv/bin/tuih", line 8, in <module>
    sys.exit(main())
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/html1.py", line 239, in main
    page = HtmlPage(results)
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/html1.py", line 88, in __init__
    self.tab_content.fetch_html()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/html1.py", line 72, in fetch_html
    for key, value in self.fetch_raw().items()
  File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/html1.py", line 57, in fetch_raw
    self.results.tui_sections.short_test_summary.content,
AttributeError: 'NoneType' object has no attribute 'short_test_summary'

jeffwright13 avatar Aug 22 '22 07:08 jeffwright13

In this case, there is a console script, defined in top-level setup.py: entry_points={"console_scripts": ["aims-qa-tests=aims_qa_tests.__main__:main"]},

....and then in aims_qa_tests/__main__.py, we have this:

def main():
    """
    Wrapper function to run pytest, targeting the folder this file resides in.
    """
    os.chdir(pathlib.Path(__file__).parent.absolute())
    pytest.main()

jeffwright13 avatar Aug 22 '22 07:08 jeffwright13

Troubleshooting tip: import os; print(os.getcwd()) In standard situation, it's at top level (e.g. ~/pytest-tui) In the modified situation, it's at a lower dir (~/toplevel/lowerlevel)

jeffwright13 avatar Aug 22 '22 07:08 jeffwright13