Merge remote-tracking branch 'upstream/master' into merge-master-into-features
# Conflicts: # _pytest/capture.py # _pytest/compat.py # _pytest/python.py # testing/python/collect.py # testing/test_mark.py
This commit is contained in:
@@ -104,6 +104,22 @@ class TestModule(object):
|
||||
else:
|
||||
assert name not in stdout
|
||||
|
||||
def test_show_traceback_import_error_unicode(self, testdir):
|
||||
"""Check test modules collected which raise ImportError with unicode messages
|
||||
are handled properly (#2336).
|
||||
"""
|
||||
testdir.makepyfile(u"""
|
||||
# -*- coding: utf-8 -*-
|
||||
raise ImportError(u'Something bad happened ☺')
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines([
|
||||
"ImportError while importing test module*",
|
||||
"Traceback:",
|
||||
"*raise ImportError*Something bad happened*",
|
||||
])
|
||||
assert result.ret == 2
|
||||
|
||||
|
||||
class TestClass(object):
|
||||
def test_class_with_init_warning(self, testdir):
|
||||
@@ -826,6 +842,34 @@ class TestConftestCustomization(object):
|
||||
l = modcol.collect()
|
||||
assert '_hello' not in l
|
||||
|
||||
def test_issue2369_collect_module_fileext(self, testdir):
|
||||
"""Ensure we can collect files with weird file extensions as Python
|
||||
modules (#2369)"""
|
||||
# We'll implement a little finder and loader to import files containing
|
||||
# Python source code whose file extension is ".narf".
|
||||
testdir.makeconftest("""
|
||||
import sys, os, imp
|
||||
from _pytest.python import Module
|
||||
|
||||
class Loader:
|
||||
def load_module(self, name):
|
||||
return imp.load_source(name, name + ".narf")
|
||||
class Finder:
|
||||
def find_module(self, name, path=None):
|
||||
if os.path.exists(name + ".narf"):
|
||||
return Loader()
|
||||
sys.meta_path.append(Finder())
|
||||
|
||||
def pytest_collect_file(path, parent):
|
||||
if path.ext == ".narf":
|
||||
return Module(path, parent)""")
|
||||
testdir.makefile(".narf", """
|
||||
def test_something():
|
||||
assert 1 + 1 == 2""")
|
||||
# Use runpytest_subprocess, since we're futzing with sys.meta_path.
|
||||
result = testdir.runpytest_subprocess()
|
||||
result.stdout.fnmatch_lines('*1 passed*')
|
||||
|
||||
def test_setup_only_available_in_subdir(testdir):
|
||||
sub1 = testdir.mkpydir("sub1")
|
||||
sub2 = testdir.mkpydir("sub2")
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import with_statement
|
||||
import pickle
|
||||
import os
|
||||
import sys
|
||||
from io import UnsupportedOperation
|
||||
|
||||
import _pytest._code
|
||||
import py
|
||||
@@ -671,7 +672,7 @@ def test_dontreadfrominput():
|
||||
pytest.raises(IOError, f.read)
|
||||
pytest.raises(IOError, f.readlines)
|
||||
pytest.raises(IOError, iter, f)
|
||||
pytest.raises(ValueError, f.fileno)
|
||||
pytest.raises(UnsupportedOperation, f.fileno)
|
||||
f.close() # just for completeness
|
||||
|
||||
|
||||
|
||||
@@ -305,6 +305,23 @@ def test_parametrized_collected_from_command_line(testdir):
|
||||
rec.assertoutcome(passed=3)
|
||||
|
||||
|
||||
def test_parametrized_collect_with_wrong_args(testdir):
|
||||
"""Test collect parametrized func with wrong number of args."""
|
||||
py_file = testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize('foo, bar', [(1, 2, 3)])
|
||||
def test_func(foo, bar):
|
||||
pass
|
||||
""")
|
||||
|
||||
result = testdir.runpytest(py_file)
|
||||
result.stdout.fnmatch_lines([
|
||||
'E ValueError: In "parametrize" the number of values ((1, 2, 3)) '
|
||||
'must be equal to the number of names ([\'foo\', \'bar\'])'
|
||||
])
|
||||
|
||||
|
||||
class TestFunctional(object):
|
||||
|
||||
def test_mark_per_function(self, testdir):
|
||||
|
||||
Reference in New Issue
Block a user