Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for pdb import ~/.pdbrc #62601

Closed
sptonkin mannequin opened this issue Jul 8, 2013 · 10 comments
Closed

Tests for pdb import ~/.pdbrc #62601

sptonkin mannequin opened this issue Jul 8, 2013 · 10 comments
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@sptonkin
Copy link
Mannequin

sptonkin mannequin commented Jul 8, 2013

BPO 18401
Nosy @terryjreedy, @ronaldoussoren, @ncoghlan, @bitdancer, @ambv
Files
  • pdb_add_readrc_kwarg.diff
  • 18401-pdb-readrc-kwarg-with-docs-and-tests.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-09-10.05:27:53.731>
    created_at = <Date 2013-07-08.05:35:46.341>
    labels = ['type-feature', 'tests']
    title = 'Tests for pdb import ~/.pdbrc'
    updated_at = <Date 2016-09-10.07:16:31.736>
    user = 'https://bugs.python.org/sptonkin'

    bugs.python.org fields:

    activity = <Date 2016-09-10.07:16:31.736>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-10.05:27:53.731>
    closer = 'lukasz.langa'
    components = ['Tests']
    creation = <Date 2013-07-08.05:35:46.341>
    creator = 'sptonkin'
    dependencies = []
    files = ['32260', '34892']
    hgrepos = []
    issue_num = 18401
    keywords = ['patch']
    message_count = 10.0
    messages = ['192614', '200600', '216188', '216372', '216954', '275570', '275571', '275573', '275575', '275588']
    nosy_count = 9.0
    nosy_names = ['terry.reedy', 'ronaldoussoren', 'ncoghlan', 'r.david.murray', 'lukasz.langa', 'python-dev', 'sptonkin', 'numerodix', 'sam.kimbrel']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18401'
    versions = ['Python 3.6']

    @sptonkin
    Copy link
    Mannequin Author

    sptonkin mannequin commented Jul 8, 2013

    After a clean check out and a successful build of Python 3.4, doctests were failing when running test_pdb. Specifically, doctests were failing because they were getting a "*** NameError: name 'execfile' is not defined" when running.

    It turns out that my ~/.pdbrc file contained a call to execfile(). While removing this line from my ~/.pdbrc file remedied the issue for me, test_pdb probably shouldn't be reading from global configuration when testing the pdb module.

    @sptonkin sptonkin mannequin assigned ronaldoussoren Jul 8, 2013
    @sptonkin sptonkin mannequin added OS-mac type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jul 8, 2013
    @ronaldoussoren ronaldoussoren removed their assignment Jul 8, 2013
    @numerodix
    Copy link
    Mannequin

    numerodix mannequin commented Oct 20, 2013

    I have been thinking about a fix for this. A straightforward fix would be to add a kwarg readrc=True to the constructor of Pdb that will default to reading the rc files as it does now, and allows disabling this default.

    The implication is that all tests in stdlib will need to use pdb.Pdb(readrc=False).set_trace() instead of just pdb.set_trace(). This would impact (from what I can see) doctest.py, test_pdb.py and test_doctest.py, and would also require some kind of warning/notice instructing test writers to follow this convention.

    I started working on a patch for this (attached), which works for test_pdb, but I can't get the tests in test_doctest to work yet.

    It would also be useful to have a test that demonstrates this problem and I'm not sure what the best approach is... should it show that doctests fail? If so, and knowing that Pdb reads rc files from a) $HOME/.pdbrc and b) ./.pdbrc, the test could:
    a) unset os.environ['HOME']
    b) use a tmpdir and put a temporary .pdbrc file there, with some invalid Python code
    c) chdir to that tmpdir

    Then to trigger the problem it could write a small script containing a doctest that internally does pdb.set_trace(), run the module and demonstrate that the doctest failed. And then teardown all the temporary resources in a finally block.

    @bitdancer
    Copy link
    Member

    Adding a parameter is an enhancement. Probably not a bad thing to have anyway, but it can only go in 3.5. Since this isn't something that causes problems for production code, that seems fine. (The alternative would be to say have a private class variable that the tests would set/reset, but that is pretty ugly).

    The final patch will need doc changes and a whatsnew entry.

    @bitdancer bitdancer added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Apr 14, 2014
    @samkimbrel
    Copy link
    Mannequin

    samkimbrel mannequin commented Apr 15, 2014

    Picked up Martin's patch and added docs, misc/NEWS entry, and a test for readrc=False behavior.

    @bitdancer
    Copy link
    Member

    Thanks, Sam. It is more helpful if the NEWS entry is *not* put in the patch given the current state of the tooling. What's needs to be added is an entry in Doc/whatsnew/3.5.

    For the new test, you can take advantage of the temp_dir and EnvironmentVarGuard helpers in test.support to simplify the code and make it more bullet proof.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 10, 2016

    New changeset ee0bbfd972de by Łukasz Langa in branch 'default':
    Issue bpo-18401: pdb tests don't read ~/.pdbrc anymore
    https://hg.python.org/cpython/rev/ee0bbfd972de

    @ambv
    Copy link
    Contributor

    ambv commented Sep 10, 2016

    Thanks for your contribution, Martin and Sam!

    @ambv ambv closed this as completed Sep 10, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 10, 2016

    New changeset 09c730db1aac by Victor Stinner in branch 'default':
    Issue bpo-18401: Fix test_pdb if $HOME is not set
    https://hg.python.org/cpython/rev/09c730db1aac

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 10, 2016

    New changeset 5aa77974dd56 by Victor Stinner in branch 'default':
    Issue bpo-18401: Fix test_pdb on Windows
    https://hg.python.org/cpython/rev/5aa77974dd56

    @terryjreedy
    Copy link
    Member

    (Copied from my post to python-checkins.)
    On Windows, HOME is spelled USERPROFILE or ,HOMEDRIVE + HOMEPATH. These are set by default on Windows. The OS specific os.path.expanduser('~') deals with this difference. I don't know what you are testing exactly, but I believe cross-platform modules should use the latter instead of the *NIX-specific HOME.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants