Skip to content

reload() doesnt work because of _should_rewrite() #3852

Closed
@fersarr

Description

@fersarr
  • Include a detailed description of the bug or suggestion

using reload(mymodule) or imp.reload(mymodule) inside a test is failing because _should_rewrite() gets called and it incorrectly thinks that mymodule is a conftest/test file when it is not and because of that it doesn't get reloaded.

The problem seems to be here:

if name == marked or name.startswith(marked + "."):

where name is

xxxx.name1.name2

and self._must_rewrite is

set(['pytest_server_fixtures', 'tests', 'common_setup', 'setup', 'xdist', 'xxxx', 'xxxx.testing.pytest.name3', 'pytest_shutil', 'conftest', 'pytest_svn', 'pytest_verbose_parametrize', 'pytest_qt_app',

*note: xxxx is our company's namespace

so,

when name is 'xxxx.name1.name2' and marked is xxxx, name.startswith(..) returns True

This seems to result from the fact that we have a testing module inside our company's namespace. It is called xxxx.testing.

This used to work on pytest 2.9.1

  • pip list of the virtual environment you are using
alembic (0.7.4)
click (6.2)
fixtures (3.0.0)
..
mock (1.0.1)
mockextras (1.0.2)
pytest (3.7.2)
pytest-cov (2.2.1)
pytest-fixture-config (1.0.1)
pytest-profiling (1.2.6)
pytest-qt-app (1.0.1)
pytest-shutil (1.2.8)
pytest-svn (1.2.2)
pytest-verbose-parametrize (1.3.0)
pytest-virtualenv (1.2.7)
pytest-xdist (1.14)
python-dateutil (2.4.2)
python-gnupg (0.3.3)
python-jenkins (0.2)
python-ldap (2.3.12)
python-mimeparse (1.5.2)
python-snappy (0.5)
python-subunit (1.2.0)
...

  • pytest and operating system versions

Python 2.7.11
64 bit Linux RHEL7
pytest 3.7.2 (also tried on 3.0.6 and 3.1.0 and 2.9.1) - only 2.9.1 worked

  • Minimal example if possible

have a namespace yyy with a namespace package yyy.testing that includes testing utilities. Then write tests for another package yyy.mymodule and use reload() inside the tests to re-initialize things inside mymodule

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions