I am trying to manipulate minted code inside my custom defined macros, however I am getting an error File ended while scanning use of \FancyVerbGetLine. A similar thing happens with comments as well which I suspect has a similar reason (though they are less important to me).
Here's a minimum (non-) working example
\documentclass{article}
\usepackage{minted}
\usepackage{xparse}
\usepackage{comment}
\NewDocumentCommand{\mytestCmd}{+m}{% a trivial command
#1}
\newenvironment{mytestEnv}{}{} % a trivial environment
\begin{document}
\mytestCmd % commenting this removes the error
{
\begin{minted}{py}
u = rand()
\end{minted}
}
\mytestCmd % commenting this removes the error
{
\begin{comment}
My comment
\end{comment}
}
\begin{mytestEnv} % Environments work without issue, but not macros
\begin{minted}{py}
u = rand()
\end{minted}
\begin{comment}
My comment
\end{comment}
\end{mytestEnv}
\end{document}
Is there a way to get minted and comment environments to work as arguments for macros?