Add a new "addopts" by default in pytest plugin? - pytest

I want to disable capture by default in a pytest plugin I'm working on. This can be done using an "ini" file normally as below:
[pytest]
addopts = -s
In the pytest docs they discuss "addini", and this works for other values I've tried but not addopts.
https://docs.pytest.org/en/latest/reference/reference.html#pytest.Parser.addini
https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_addoption
An alternative way to approach is to override the argument directly like so:
def pytest_addoption(parser):
parser.addoption(
"--capture",
dest="capture",
help="Capture the output",
default='no'
)
...but this complains that there is an argument conflict with the existing capture argument.
Is there some other better practice for default values of addopts that I haven't thought of?

Related

how to negate a marker inside the test file

I'm running pytests on different controllers.
I have defined markers for each of my test targets
#pytest.mark.pcm33
#pytest.mark.pcm21
#pytest.mark.pcm62
#pytest.mark.pcm52
#pytest.mark.pcm61
def test_something():
So when I run pytest -m pcm62 the test test_something is executed.
Now I have a test which must be executed on all my controllers, except for pcm62.
How can I negate this, so the test is always executed, except for pcm62, something like this
#pytest.notmark.pcm62
def test_something_except_for_pcm62():
But all that I can do is this:
#pytest.mark.pcm33
#pytest.mark.pcm21
##pytest.mark.pcm62
#pytest.mark.pcm52
#pytest.mark.pcm61
def test_something_except_for_pcm62():
Notice that the more controllers I get to support, the longer my list of marker decorators gets.
pytest -m "not pcm62" does not do the trick because then I can not use the initial test_something in the same script.

Collect py.test tests info with markers

I'm using py.test and I want to get the list of tests that I have with marker info included.
When I use the --collect-only flag I get the test functions. Is there a way to get the assigned markers for each test also?
Based on Frank T's answer I created a workaround code sample:
from _pytest.mark import MarkInfo, MarkDecorator
import json
def pytest_addoption(parser):
parser.addoption(
'--collect-only-with-markers',
action='store_true',
help='Collect the tests with marker information without executing them'
)
def pytest_collection_modifyitems(session, config, items):
if config.getoption('--collect-only-with-markers'):
for item in items:
data = {}
# Collect some general information
if item.cls:
data['class'] = item.cls.__name__
data['name'] = item.name
if item.originalname:
data['originalname'] = item.originalname
data['file'] = item.location[0]
# Get the marker information
for key, value in item.keywords.items():
if isinstance(value, (MarkDecorator, MarkInfo)):
if 'marks' not in data:
data['marks'] = []
data['marks'].append(key)
print(json.dumps(data))
# Remove all items (we don't want to execute the tests)
items.clear()
I don't think pytest has built-in behavior to list test functions along with the marker information for those tests. A --markers command lists all registered markers, but that's not what you want. I briefly looked over the list of pytest plugins and didn't see anything that looked relevant.
You can write your own pytest plugin to list tests along with marker info. Here is documentation on writing a pytest plugin.
I would try using the "pytest_collection_modifyitems" hook. It is passed a list of all tests that are collected, and it doesn't need to modify them. (Here is a list of all hooks.)
The tests passed in to that hook have a get_marker() method if you know the name of the marker you're looking for (see this code for example). When I was looking through that code, I could not find an official API for listing all markers. I found this to get the job done: test.keywords.__dict__['_markers'] (see here and here).
You can find markers by a name attribute in the request.function.pytestmark object
#pytest.mark.scenarious1
#pytest.mark.scenarious2
#pytest.mark.scenarious3
def test_sample():
pass
#pytest.fixture(scope='function',autouse=True)
def get_markers():
print([marker.name for marker in request.function.pytestmark])
>>> ['scenarious3', 'scenarious2', 'scenarious1']
Note, that they were listed in the reversed order by default.

How to get PyTest fixtures to autocomplete in PyCharm (type hinting)

I had a bear of a time figuring this out, and it was really bugging me, so I thought I'd post this here in case anyone hit the same problem...
(and the answer is so dang simple it hurts :-)
The Problem
The core of the issue is that sometimes, not always, when dealing with fixtures in PyTest that return objects, when you use those fixtures in a test in PyCharm, you don't get autocomplete hints. If you have objects with large numbers of methods you want to reference while writing a test, this can add a lot of overhead and inconvenience to the test writing process.
Here's a simple example to illustrate the issue:
Let's say I've got a class "event_manager" that lives in:
location.game.events
Let's further say that in my conftest.py file (PyTest standard thing for the unfamiliar), I've got a fixture that returns an instance of that class:
from location.game.events import event_manager
...
#pytest.fixture(scope="module")
def event_mgr():
"""Creates a new instance of event generate for use in tests"""
return event_manager()
I've had issues sometimes, (but not always - I can't quite figure out why) with classes like this where autocomplete will not work properly in the test code where I use the fixture, e.g.
def test_tc10657(self, evt_mgr):
"""Generates a Regmod and expects filemod to be searchable on server"""
evt_mgr.(This does not offer autocomplete hints when you type ".")
So the answer is actually quite simple, once you review type hinting in PyCharm:
http://www.jetbrains.com/help/pycharm/2016.1/type-hinting-in-pycharm.html
Here's how to fix the above test code so that autocomplete works properly:
from location.game.events import event_manager
...
def test_tc10657(self, evt_mgr: event_manager):
"""Generates a Regmod and expects filemod to be searchable on server"""
evt_mgr.(This DOES offer hints when you type "." Yay!)
Notice how I explicitly type the fixture as an input parameter of type event_manager.
Also if you add a docstring to a function and specify the type of the the parameters, you will get the code completion for those parameters.
For example using pytest and Selenium:
# The remote webdriver seems to be the base class for the other webdrivers
from selenium.webdriver.remote.webdriver import WebDriver
def test_url(url, browser_driver):
"""
This method is used to see if IBM is in the URL title
:param WebDriver browser_driver: The browser's driver
:param str url: the URL to test
"""
browser_driver.get(url)
assert "IBM" in browser_driver.title
Here's my conftest.py file as well
import pytest
from selenium import webdriver
# Method to handle the command line arguments for pytest
def pytest_addoption(parser):
parser.addoption("--driver", action="store", default="chrome", help="Type in browser type")
parser.addoption("--url", action="store", default='https://www.ibm.com', help="url")
#pytest.fixture(scope='module', autouse=True)
def browser_driver(request):
browser = request.config.getoption("--driver").lower()
# yield the driver to the specified browser
if browser == "chrome":
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
else:
raise Exception("No driver for browser " + browser)
yield driver
driver.quit()
#pytest.fixture(scope="module")
def url(request):
return request.config.getoption("--url")
Tested using Python 2.7 and PyCharm 2017.1. The docstring format is reStructuredText and the "Analyze Python code in docstrings" checkbox is checked in settings.

How do i use tags in selenium tests using the Scala module for Playframework?

I've read the docs on tags for the normal templates:
scala-0.9.1/templates#Tags
Now I'm trying to create a login-tag to be used in my selenium tests but I can't seem to get it to work.
In play for Java I have this:
# in file app/views/tags/test/loginAs.html
click('link=Log in')
type('css=.login input[name=email]', '${_email}')
type('css=.login input[name=password]', '${_password}')
clickAndWait('css=.login input[type=submit]')
In a test I use it like this:
#{test.loginAs email:'foo#bar.com', password:'1234' /}
Using Play with Scala I have tried this:
# in file app/views/tags/test/loginAs.scala.html
#(username:String, password: String)(body: (String) => Html)
click('link=Log in')
type('css=.login input[name=email]', '#email')
type('css=.login input[name=password]', '#password')
clickAndWait('css=.login input[type=submit]')
And in my test i first do the import:
import views.tags.html._
But when I call it from my test like so:
#loginAs("foo#bar.com", "1234")
I get no error, but no selenium code in my test either...
What I'm I doing wrong?
Edit
So, it turns out you don't have to use the Scala templates... I tried to use the "normal" templates like the one I described above and It works fine.

How do I get a list of members in a Python module, or how should I create plugins?

I'm writing a sort of dashboard-esque program in Python to make tasks that I do frequently here at work a little better/easier.
What I currently have set up is an actions module. actions contains an actionlist that is a list of classes. Each of my classes has a .title, .icon (base-64 encoded string for use with tkinter.PhotoImage), and a .action function.
Using tkinter I create a new button for each of these actions, with the appropriate icon, text, and the command of the button set to the .action. So far it works quite nicely, but if I want to create a new action, I have to go into my actions module, create a new class, and then put that class in my actionlist.
What I would like to do is be able to dynamically generate this actionlist based on what files are present in my module. So I would like to have something like this:
actions/
__init__.py
someaction.py
do_another_thing.py
do_all_the_things.py
chop_down_the_tree_with_a_herring.py
And whenever I would like to create a new action, I just put a .py script in my actions folder and then it would automagically generate the list of actions for me, however I can't seem to find any good way of creating this list. I've thought of using something like os.listdir to get the list of files, but neither that or the other methods of introspection (dir, and inspect.getmembers) seemed to have quite what I wanted. Of course, it's possible that I just missed the features that I need.
In any case, pointers in the right direction would be great. Thanks!
SOLUTION:
Lennart's solution, with some slight adaptations worked for me.
Inside my __init__.py I have the following code:
plugins = []
__all__ = [
'do_all_the_things',
'do_another_thing',
'someaction',
'chop_down_the_tree_with_a_herring',
'seek_the_grail',
]
Then inside each of my plugins I have something like this:
from actions import plugins
class SeekTheGrail:
def __init__(self):
self.text = 'We Seek The Grail'
self.icon = b'R0lGODlhkABJAPcAABsVGH6DWWaElDxIdU1LM8mxc2RnQ3iFaLi8mLmQZqxpOy4rPq28y41NNTMvJIujl5qbakpMTdubSWJoV4KhxOfTnkBYoL+EQ26FgF84LtzZyaRoTFdbPLm/sK+hnH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0AOtCQAcSIcloIZs8AYXkA+86wEovoZjUMYIEYIwqIobYQF0qbS8SehmeADj6YdAKAIGKAIkEIQRiAV8qFBiMII0poKObt02aAIahDUe2QM+mEcNpo1t+ZYWk0oOxLo9QI41YIYkIIJzIAKaPodEJoLJ/mkr+AUiOADjiBtA4YAjKIBMiI9iUIP0mw+m1hJZokwWuKdWqjcJEZUlmpMIwIBGeM+uAed+eEnU3IcSfZgEAaAFWpgEGiCGBZbGqwoIADs='
def action(self):
print('I am Arthur, King of the Britons!')
plugins.append(SeekTheGrail())
and now I just have to modify the __all__ collection when I want to add or remove the actions from loading.
The way to create plugins is to have a plugin registry, and register plugins there. This can be done from the amazingly simple, like just defining a global list in a module:
plugins = []
And then registering the plugins with:
class APlugin(object):
blahblah
from themodule import plugins
plugin.add(APlugin())
This can be made more flexible by having types of plugins and registering them with a name etc. But then you are on the path to complexity, and then you might want to take a look at the Zope Component Architecture, which simply speaking is a very powerful system for making your application pluggable.
It should be noted that in any case it's best to have a list of what plugins should be activated instead of auto-discovering them. This can be as simple as a list in a text file or a setting in a config file. This enables you to easily activate and disactivate the plugins.
You can use something like this:
actions = {}
for filename in os.listdir('somepath/actions'):
actions[filename] = __import__('actions.'+filename)
for name,class in actions:
createButton(name,class)
Where in the createButton you create your tk_inter button and assign it the functions from the class. The important bit i suppose is that you can use __import__ to import a class using its string name and save it as a variable.