Closed nicholaskeytholeong closed 10 years ago
--with-save-baseline
is in fact a nose plugin: https://github.com/bfirsh/needle/blob/master/needle/plugin.py#L24
When using pytest, you would have to set an environment variable:
$ NEEDLE_SAVE_BASELINE=true pytest ...
I'm not sure if pytest has a similar way for adding custom parameters to the command line. If so, then we could consider adding that to Needle. Regardless, the use of the environment variable should probably be documented.
Found a quick workaround ...
import logging
import os
# Configure logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.FileHandler('needletest.log')
handler.setLevel(logging.INFO)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
def pytest_addoption(parser):
group = parser.getgroup("Base options to run Needle tests")
group._addoption('--baseurl',
action='store',
dest='base_url',
default=None,
help='Target base URL')
group._addoption('--save-baseline',
action='store_true',
dest='save_baseline',
default=False,
help='Capture screen baseline')
def pytest_configure(config):
if config.option.save_baseline:
os.environ["NEEDLE_SAVE_BASELINE"] = "1"
import logging
import os
import pytest
from needle.cases import NeedleTestCase
option = pytest.config.option
class TestNeedle(NeedleTestCase):
def test_login_pg(self):
logging.info(option)
self.driver.get(option.base_url)
self.set_viewport_size(width=1024, height=768)
self.assertScreenshot('div.account', 'loginform')
py.test --baseurl=http://some-local-working-env --save-baseline needledemo.py
Currently using needle 0.2.2
Got this error when trying to run needle with pytest