Skip to content

Pytest Exe Not Found Using envrc and direnv #56

@tompurl

Description

@tompurl

I see in your readme that you recommend the direnv.el to help with my type of setup, but I have had very good luck with the envrc.el plugin (which is tightly integrated with Doom Emacs) and would prefer not to switch if possible. However I understand if my configuration simply isn't supported and appreciate your contributions to the Emacs and Python communities.


I am using lorri with direnv to setup my dev environment. I also use the latest stable Doom Emacs distro.

Here are the contents of my shell.nix file:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    pkgs.hello
    pkgs.python3
    pkgs.poetry
    pkgs.pyright
    pkgs.python39Packages.pytest
    pkgs.python39Packages.pytestrunner

    # keep this line if you use bash
    pkgs.bashInteractive
  ];
}

Here are the contents of my .envrc file:

eval "$(lorri direnv)"

What I would like to do is execute the python-pytest-file command from a buffer called matrix.py that is in the same directory as a file called matrix_test.py. Instead I get the following error:

cwd: /home/tom/exercism/
cmd: pytest --color=yes python/matrix/matrix.py

/usr/bin/sh: 1: pytest: not found

This path error is surprising to me because I can access the pytest executable from other Python dev plugins in Emacs. My understanding was that the envrc.el managed this.

For example, when I'm viewing my Python buffer and I open a new Emacs vterm buffer I can do the following:

direnv: loading ~/exercism/python/.envrc
direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +DETERMINISTIC_BUILD +HOST_PATH +IN_LORRI_SHELL +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_INDENT_MAKE +NIX_LDFLAGS +NIX_LOG_FD +NIX_STORE +NM +OBJCOPY +OBJDUMP +PYTHONHASHSEED +PYTHONNOUSERSITE +PYTHONPATH +RANLIB +READELF +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +_PYTHON_HOST_PLATFORM +_PYTHON_SYSCONFIGDATA_NAME +allowSubstitutes +buildInputs +builder +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +extraClosure +name +nativeBuildInputs +nobuildPhase +origArgs +origBuilder +origExtraClosure +origOutputs +origPATH +origSystem +out +outputs +patches +phases +preHook +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS
tom@janet:~/exercism/python/matrix$ which pytest
/nix/store/ss47q6p4kczpmzshgr56wd9bqmg08ibm-python3.9-pytest-6.2.5/bin/pytest

When viewing my Python buffer I can also run the pytest command from the M-! prompt.

I've also tried "refresing" my direnv environment by executing the envrc-reload and lsp-restart-workspace commands multiple times.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions