Commit f91d59f
authored
Fix issue with
Hi,
can you please review patch to address the `basilisp test` failure on
MS-Windows. It fixes #1080.
The problem arises because pytest's mechanism for capturing standard
streams during tests breaks when those streams are saved before
pytest.main is called and then used in the test. This happens when
running `basilisp test` from the CLI:
In `basilisp.init`, `sys.stdout` and `sys.stderr` are saved to the
`*out*` and `*err*` dynamic variables before `pytest.main` is called. If
a test prints anything, it tries to write to these original streams,
causing failures due to an issue I just reported in
pytest-dev/pytest#12876.
This patch rebinds `*out*` and `*err*` to the streams set by `pytest`
and restores them when `pytest` finishes (via the `configure`
functions). I've tested it with a case that prints to `*out*` and
`*err*` at the top level, inside a test, and inside a fixture, and it
works as expected.
```clojure
(ns tests.issuetests.issue-test
(:require [basilisp.test :refer [deftest are is testing use-fixtures]])
(:import sys))
(println :top-out)
(binding [*out* *err*]
(println :top-err))
(defn fixture-gen-test []
(println :fix-gen-out)
(yield)
(binding [*out* *err*]
(println :fix-gen-err)))
(use-fixtures :each fixture-gen-test)
(deftest print_test
(println :test-out)
(is (= 5 5))
(binding [*out* *err*]
(println :test-err)))
```
```powershell
> basilisp test
=============================================================================================================== test session starts ================================================================================================================
platform win32 -- Python 3.11.4, pytest-8.4.0.dev100+g410c51011, pluggy-1.5.0
rootdir: C:\clj\issues\issue-bas-test-macro-print
configfile: pyproject.toml
plugins: basilisp-0.2.4
collecting ... :top-out
:top-err
collected 1 item
tests\issuetests\issue_test.lpy :fix-gen-out
:test-out
:test-err
.:fix-gen-err
```
I’d also like to discuss `Basilisp` integration tests, which I think the
above testing falls under, though there’s currently no support for such
tests in `Basilisp`.
Ideally I think, I would like to create a `Basilisp` project in a
temporary directory, add the above test, install the fix alongside
`pytest`, activate the environment, and then run `basilisp test`.
Do you have any suggestions how to extend the `Basilisp` test suite to
implement this? or shall I open a new ticket for this discussion? I was
thinking of having a new `--integration` pytest option for these tests,
something I have been experimenting with in the basilisp-blender
package.
Thanks
---------
Co-authored-by: ikappaki <[email protected]>basilisp test standard streams output (#1082)1 parent efb62a1 commit f91d59f
2 files changed
+37
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | | - | |
25 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
26 | 52 | | |
27 | 53 | | |
28 | 54 | | |
29 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
30 | 63 | | |
31 | 64 | | |
32 | 65 | | |
| |||
0 commit comments