From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Alsinet Subject: Re: [Proposal] Source Blocks with Post-Extensions Date: Fri, 26 Jul 2019 07:58:36 -0500 Message-ID: References: <87a7d10zss.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006ca05e058e951a2c" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:54732) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqzoD-0001fi-U0 for emacs-orgmode@gnu.org; Fri, 26 Jul 2019 08:58:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqzoC-0000CU-Gh for emacs-orgmode@gnu.org; Fri, 26 Jul 2019 08:58:53 -0400 Received: from mail-ot1-f42.google.com ([209.85.210.42]:46827) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hqzoC-0008Vr-8k for emacs-orgmode@gnu.org; Fri, 26 Jul 2019 08:58:52 -0400 Received: by mail-ot1-f42.google.com with SMTP id z23so26890046ote.13 for ; Fri, 26 Jul 2019 05:58:48 -0700 (PDT) In-Reply-To: <87a7d10zss.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Ken Mankoff Cc: Dmitrii Korobeinikov , emacs-orgmode , "Berry, Charles" --0000000000006ca05e058e951a2c Content-Type: text/plain; charset="UTF-8" Ken, I usually have a shell buffer nearby and go there to inspect the failed tests when I get no output. The problem is that shell blocks do not capture stderr. John Kitchin wrote a blog post about this problem and provided a solution that may work for you, but I have not tried it yet. Martin On Fri, Jul 26, 2019 at 7:02 AM Ken Mankoff wrote: > Hi Martin, > > On 2019-06-26 at 18:09 -04, Martin Alsinet > wrote... > > I use a different approach, where I tangle the source into files in > > modules and then I import those modules from other blocks. This allows > > me to organize my document with different sections for the code and > > its tests, which then get exported into their corresponding files. > > Thanks for providing this pytest code below. It runs nicely because your > tests pass. It does not run if a test fails. The shell block that runs > pytest reports > > Babel evaluation exited with code 1 > Code block produced no output. > > Do you have some way of capturing failed pytest tests in Org Babel? > > Thanks, > > -k. > > > * Square Function > > > > This function receives a number and returns its square > > > > #+BEGIN_SRC python :tangle ./utils/math.py :mkdirp yes > > def square(x): > > return x * x > > #+END_SRC > > > > ** __init__.py (module setup) > > > > #+begin_src python :tangle ./utils/__init__.py :mkdirp yes > > from utils.math import square > > > > #+end_src > > > > ** Test cases > > > > 1. The square of five should be 25 > > 2. The square of zero should be 0 > > 3. The square of a negative number should be positive > > > > #+BEGIN_SRC python :tangle ./utils/test_square.py :mkdirp yes > > from utils.math import square > > > > def test_square_of_five(): > > assert square(5) == 25 > > > > def test_square_of_zero(): > > assert square(0) == 0 > > > > def test_square_of_negative(): > > assert square(-5) > 0 > > #+END_SRC > > > > *** Run tests > > > > #+begin_src sh :results output raw > > pytest ./utils > > #+end_src > > > > #+RESULTS: > > ============================= test session starts > > ============================== > > platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0 > > rootdir: /app > > collected 3 items > > > > utils/test_square.py ... > > [100%] > > > > =========================== 3 passed in 0.08 seconds > > =========================== > > > > > --0000000000006ca05e058e951a2c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ken,

I usually have a shell buffer near= by and go there to inspect the failed tests when I get no output.
The p= roblem is that shell blocks do not capture stderr. John Kitchin wrote a blog post about this problem and provided = a solution that may work for you, but I have not tried it yet.

Martin

On Fri, Jul 26, 2019 at 7:02 AM Ken Mank= off <mankoff@gmail.com> wrot= e:
Hi Martin,

On 2019-06-26 at 18:09 -04, Martin Alsinet <martin@alsinet.com.ar> wrote...
> I use a different approach, where I tangle the source into files in > modules and then I import those modules from other blocks. This allows=
> me to organize my document with different sections for the code and > its tests, which then get exported into their corresponding files.

Thanks for providing this pytest code below. It runs nicely because your te= sts pass. It does not run if a test fails. The shell block that runs pytest= reports

Babel evaluation exited with code 1
Code block produced no output.

Do you have some way of capturing failed pytest tests in Org Babel?

Thanks,

=C2=A0 -k.

> * Square Function
>
> This function receives a number and returns its square
>
> #+BEGIN_SRC python :tangle ./utils/math.py :mkdirp yes
> def square(x):
>=C2=A0 =C2=A0 =C2=A0return x * x
> #+END_SRC
>
> ** __init__.py (module setup)
>
> #+begin_src python :tangle ./utils/__init__.py :mkdirp yes
> from utils.math import square
>
> #+end_src
>
> ** Test cases
>
> 1. The square of five should be 25
> 2. The square of zero should be 0
> 3. The square of a negative number should be positive
>
> #+BEGIN_SRC python :tangle ./utils/test_square.py :mkdirp yes
> from utils.math import square
>
> def test_square_of_five():
>=C2=A0 =C2=A0 =C2=A0assert square(5) =3D=3D 25
>
> def test_square_of_zero():
>=C2=A0 =C2=A0 =C2=A0assert square(0) =3D=3D 0
>
> def test_square_of_negative():
>=C2=A0 =C2=A0 =C2=A0assert square(-5) > 0
> #+END_SRC
>
> *** Run tests
>
> #+begin_src sh :results output raw
> pytest ./utils
> #+end_src
>
> #+RESULTS:
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D test session starts
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D
> platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0<= br> > rootdir: /app
> collected 3 items
>
> utils/test_square.py ...
> [100%]
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D 3 passed in 0.08 seconds
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D
>
>
--0000000000006ca05e058e951a2c--