How do I solve the 'pytest not found command' error in Jenkins

For anyone struggling with this - the problem was with rules precedence inside /etc/sudoers.

By default if there are multiple entries for a user inside of the /etc/sudoers file, sudo uses the last rule that applies

The change to jenkins user was being overridden because of the rule’s position in /etc/sudoers :

WRONG
image

It is wrong because jenkins user is already a member of sudo group, and thus the line jenkins ALL=(ALL) NOPASSWD: ALL will be overriden by the line

sudo ALL=(ALL:ALL) ALL

CORRECT