pytest-dev / pytest-dev/pytest
Allow to execute classmethods without instantiating the class if possible
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
I would like to run a test function with pytest without having to set up a pytest.ini, using only command line arguments. The test function is a class method with no arguments (not an instance method). It is named 'test' and defined in the 'Stack' class in the current directory's file, "stack.py". The code can be seen here.
However, calling:
pytest stack.py::Stack::test
fails to work as shown below. Is there any way to make this work with a change in syntax or is this a bug?
========================================================================
test session starts
========================================================================
platform darwin -- Python 3.6.2, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /Users/rsw/rsw_py_stack, inifile:
collecting 0 items
===================================================================
no tests ran in 0.00 seconds
====================================================================
ERROR: not found: /Users/rsw/rsw_py_stack/stack.py::Stack::test
(no name '/Users/rsw/rsw_py_stack/stack.py::Stack::test' in any of [<Module 'stack.py'>])
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the command pytest stack.py::Stack::test against the linked example, then trace how pytest collects the Stack class and its classmethod. Done means the command-line target is found and the no-argument classmethod runs without requiring pytest.ini or an instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100