pytest-dev / pytest-dev/pytest

add option using dynamically loaded plugin class - unrecognized arguments

Open
#6,383 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: config
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

description

I try to run pytest with dynamically loaded plugin class with pytest_addoption hook.
The cmd options in the plugin hook do not added to the parser. So pytest exists with error 'unrecognized arguments':

(issue_with_pytest_add_option) $ pytest --feature test
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --feature
  inifile: None
  rootdir: /home/alsoroki/src/issue_with_pytest_add_option

output of pip list from the virtual environment you are using

(issue_with_pytest_add_option)  $ pip list
Package            Version
------------------ -------
attrs              19.3.0 
importlib-metadata 1.3.0  
more-itertools     8.0.2  
packaging          19.2   
pip                19.3.1 
pkg-resources      0.0.0  
pluggy             0.13.1 
py                 1.8.1  
pyparsing          2.4.6  
pytest             5.3.2  
setuptools         42.0.2 
six                1.13.0 
wcwidth            0.1.7  
wheel              0.33.6 
zipp               0.6.0  

pytest and operating system versions

(issue_with_pytest_add_option)  $ issue_with_pytest_add_option pytest --version
This is pytest version 5.3.2, imported from /home/user/.virtualenvs/issue_with_pytest_add_option/lib/python3.6/site-packages/pytest/__init__.py
$ uname -a
Linux pcname 4.15.0-33-generic #36~16.04.1-Ubuntu SMP Wed Aug 15 17:21:05 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Minimal example (aka steps to reproduce)

  1. Extract minimal_example.zip to a separate folder and cd there
  2. Create and activate virtual env: $ mkvirtualenv --python=python3.6 issue_with_pytest_add_option
  3. Run tests: (issue_with_pytest_add_option) $ pytest --feature test
  4. Note the error py.test: error: unrecognized arguments: --feature

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by extracting minimal_example.zip and running pytest --feature test in the Python 3.6 environment described. Trace how the dynamically loaded plugin's pytest_addoption hook is handled and why --feature is rejected as unrecognized. Done means the reproduced command accepts the plugin-defined option without the reported parser error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.