nschloe/pytest-codeblocks

Supporting Bash code blocks and more advanced combining

Closed this issue · 5 comments

Hi, thanks for your work with this repo. I forked this repo a long time ago, added some things to it and then haven't touched it since. I wanted to know your opinion on some of the changes I made and whether they're something you'd be interested in implementing here yourself (or accepting via a pull request).

  1. Supporting bash codeblocks. I added this by detecting code blocks for bash and then adding some wrapping around it to run the commands in a subprocess in Python for pytest compatibility. I saved the stdout and validated it using custom Python commands in markdown annotations (see the code and the test case). In theory, you could support any language provided the appropriate backend existed in your code to deal with the language.
  2. Combining multiple code blocks. I see you've added this with your 'cont' annotation. I had something similar where it would by default combine with the previous code block but you could also specify an index to combine it with a particular one (see this test case).

It's been a while since I looked at my own code but if there's anything I can do to help, let me know.

Thanks for the suggestions! I just added support for shell scripts at #48.

As for the combine index, I don't think there's enough use to justify the code complication.

Wow, that was fast! Thank you!

Fair enough. I see that pytest-codeblocks:cont prefix respects the pytest-codeblocks:skip prefix so I guess you can work around it.

There is an issue though. By default, subprocess shell=true uses /bin/sh which may or may not be bash (e.g. on my ubuntu, it's dash). For code blocks labeled with bash, you'd need to explicitly use bash. For example, this valid bash script fails to run.

foo=1
if [[ $foo == 1 ]]; then
    echo abc
fi
abc

Let's close this then.

Not sure if you got a notification for my previous comment since I commented/you closed at the same time. There's a bug in the bash implementation.