Skip to content

Commit c32675e

Browse files
authored
Merge pull request #26 from nicoddemus/race-condition-on-collect
Race condition on collect
2 parents 7e627f8 + 3bbe7e7 commit c32675e

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.4.1 #
2+
3+
- Fix error that may happen during collection when using xdist (#25).
4+
15
# 0.4.0 #
26

37
- Integrated most of the examples found in boost-1.55 for Boost Test into the
@@ -32,4 +36,4 @@ it behave correctly if a test writes in `std::cout` or `std::cerr`.
3236

3337
# 0.1.0 #
3438

35-
Support for Google Test and Boost Test.
39+
Support for Google Test and Boost Test.

pytest_cpp/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414

1515
def pytest_collect_file(parent, path):
16-
is_executable = os.stat(str(path)).st_mode & stat.S_IXUSR
16+
try:
17+
is_executable = os.stat(str(path)).st_mode & stat.S_IXUSR
18+
except OSError:
19+
# in some situations the file might not be available anymore at this point
20+
return False
1721
if not is_executable:
1822
return
1923
masks = parent.config.getini('cpp_files') or DEFAULT_MASKS

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="pytest-cpp",
6-
version='0.4',
6+
version='0.4.1',
77
packages=['pytest_cpp'],
88
entry_points={
99
'pytest11': ['cpp = pytest_cpp.plugin'],

tests/test_pytest_cpp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ def test_passing_files_directly_in_command_line(testdir, exes):
241241
result.stdout.fnmatch_lines(['*1 passed*'])
242242

243243

244+
def test_race_condition_on_collect(tmpdir):
245+
"""
246+
Check that collection correctly handles when a path no longer is valid.
247+
248+
This might happen in some situations when xdist is collecting multiple files, and that
249+
causes temporary .pyc files to be generated; in those situations, pytest may obtain that
250+
filename and ask plugins if they can collect it, but by the time a plugin is called
251+
the file may be gone already:
252+
253+
OSError: [Errno 2] No such file or directory:
254+
'/../test_duplicate_filenames.cpython-27-PYTEST.pyc.21746'
255+
"""
256+
import pytest_cpp.plugin
257+
assert not pytest_cpp.plugin.pytest_collect_file(None, tmpdir / 'invalid-file')
258+
259+
244260
class TestError:
245261

246262
def test_get_whitespace(self):

0 commit comments

Comments
 (0)