Skip to content

basilisp test fails when attempting to print anything out from inside a test file on MS-Windows #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ikappaki opened this issue Oct 6, 2024 · 1 comment · Fixed by #1082
Labels
component:testing Issue pertaining to tests/testing issue-type:bug Something isn't working

Comments

@ikappaki
Copy link
Contributor

ikappaki commented Oct 6, 2024

Hi,

when running basilisp test, an error occurs when trying to print from a test file

    (.write stdout os/linesep)
E   OSError: [WinError 6] The handle is invalid

To reproduce,

  1. Clone https://github.com/ikappaki/issue-bas-test-macro-print example project, and setup
git clone https://github.com/ikappaki/issue-bas-test-macro-print
cd issue-bas-test-macro-print
poetry install
poetry shell
  1. Run the tests with basilisp, you should see the error
basilisp test

==================================================== test session starts ====================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issue-bas-test-macro-print
configfile: pyproject.toml
plugins: basilisp-0.2.4
collected 0 items / 1 error

========================================================== ERRORS ===========================================================
_____________________________________ ERROR collecting tests/issuetests/issue_test.lpy ______________________________________
...
During handling of the above exception, another exception occurred:
tests\issuetests\issue_test.lpy:4: in <module>
    (println :calc (+ 5 3))
..\issuetests\.venv\Lib\site-packages\basilisp\core.lpy:4376: in println
    (defn println
..\issuetests\.venv\Lib\site-packages\basilisp\core.lpy:4398: in println__arity_rest
    (.write stdout os/linesep)
E   OSError: [WinError 6] The handle is invalid
===================================================== warnings summary ======================================================
..\issuetests\.venv\Lib\site-packages\_pytest\config\__init__.py:1277
  d:\bas\issuetests\.venv\Lib\site-packages\_pytest\config\__init__.py:1277: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: basilisp
    self._mark_plugins_for_rewrite(hook)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================== short test summary info ==================================================
ERROR tests/issuetests/issue_test.lpy - OSError: [WinError 6] The handle is invalid
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================ 1 warning, 1 error in 0.11s ================================================
:calc 8

The test file just tries to printout a value (I've also added a test event though is irrelevant)

(ns tests.issuetests.issue-test
  (:require [basilisp.test :refer [deftest are is testing]]))

(println :calc (+ 5 3))

(deftest 5-test []
  (is (= 5 5)))

Commenting out the println form allows the test to run without error.

This could as well be a MS-Windows only issue, I haven't had the chance to test on another architecture yet.

Thanks

@ikappaki ikappaki changed the title basilisp test fails when attempting to print anything out from inside a test file basilisp test fails when attempting to print anything out from inside a test file on MS-Windows Oct 7, 2024
@ikappaki
Copy link
Contributor Author

ikappaki commented Oct 7, 2024

This issue is specific to MS-Windows and works fine on Linux.

It only occurs when pytest is invoked programmatically.

Here are a couple of workarounds

  1. Instruct pytest not to capture output
> basilisp test -- -s
==================================================== test session starts ====================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
configfile: pyproject.toml
plugins: basilisp-0.2.4
collecting ... :calc 8
collected 1 item

tests\issuetests\issue_test.lpy .

===================================================== 1 passed in 0.03s =====================================================
  1. Run pytest directly, ensure the empty dir is added to the PYTHONPATH so it can pick up the local directory. For example on PowerShell:
> $env:PYTHONPATH="."
> pytest
==================================================== test session starts ====================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
configfile: pyproject.toml
plugins: basilisp-0.2.4
collecting ... :calc 8
collected 1 item

tests\issuetests\issue_test.lpy .                                                                                      [100%]

===================================================== 1 passed in 0.02s =====================================================

I'll have a look. Thanks

@chrisrink10 chrisrink10 added issue-type:bug Something isn't working component:testing Issue pertaining to tests/testing labels Oct 13, 2024
@chrisrink10 chrisrink10 added this to the Release v0.3.0 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:testing Issue pertaining to tests/testing issue-type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants