Title: Adding directory to PymodeRope · Issue #1159 · python-mode/python-mode · GitHub
Open Graph Title: Adding directory to PymodeRope · Issue #1159 · python-mode/python-mode
X Title: Adding directory to PymodeRope · Issue #1159 · python-mode/python-mode
Description: Using the python project scheme suggested by the pytest documentation, pymode does not include the tests/ directory into its ropeproject when the “include method” of the src/ directory is done via an editable install (pip install -e .). ...
Open Graph Description: Using the python project scheme suggested by the pytest documentation, pymode does not include the tests/ directory into its ropeproject when the “include method” of the src/ directory is done via ...
X Description: Using the python project scheme suggested by the pytest documentation, pymode does not include the tests/ directory into its ropeproject when the “include method” of the src/ directory is done via ...
Opengraph URL: https://github.com/python-mode/python-mode/issues/1159
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding directory to PymodeRope","articleBody":"Using the [python project scheme suggested by the pytest documentation](https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#tests-outside-application-code), pymode does not include the `tests/` directory into its `ropeproject` when the “include method” of the `src/` directory is done via an editable install (`pip install -e .`).\r\n\r\nHow do I add an additional source directory to `PymodeRope`, namely the `tests/` directory?\r\n\r\n### Minimal working example\r\nFirst create a `venv` virtual environment as well as a temporary directory. The abbreviation `pmt` stands for “pymode test”.\r\n```bash\r\n$ mkdir -p /tmp/pmt/{.venv,src/pmt,tests}\r\n$ cd /tmp/pmt\r\n$ python -m venv /tmp/pmt/.venv/pmt\r\n$ source /tmp/pmt/.venv/pmt/bin/activate\r\n(pmt) $ python -m pip install -U pip\r\n(pmt) $ python -m pip install build pytest\r\n(pmt) $ touch pyproject.toml src/pmt/__init__.py\r\n```\r\nCreate the three source files with an editor of your choice, namely\r\n* ```python\r\n # ––– file /tmp/pmt/src/pmt/spam.py\r\n def spamfunc() -> int:\r\n return 1\r\n ```\r\n* ```python\r\n # ––– file /tmp/pmt/src/pmt/bacon.py\r\n from .spam import spamfunc\r\n \r\n \r\n def baconfunc() -> None:\r\n return 1 + spamfunc()\r\n ```\r\n* ```python\r\n # ––– file /tmp/pmt/tests/test_pmt.py\r\n from pmt.bacon import baconfunc\r\n from pmt.spam import spamfunc\r\n \r\n \r\n def test_baconfunc() -> None:\r\n assert 2 == baconfunc()\r\n \r\n \r\n def test_spamfunc() -> None:\r\n assert 1 == spamfunc()\r\n ```\r\nThe project directory will look like this:\r\n```\r\n.\r\n├── pyproject.toml\r\n├── src\r\n│ └── pmt\r\n│ ├── bacon.py\r\n│ ├── __init__.py\r\n│ └── spam.py\r\n└── tests\r\n └── test_pmt.py\r\n```\r\nAs suggested by `pytest`, install the editable version of the package and invoke `pytest`:\r\n```text\r\n(pmt) $ python -m pip install -e .\r\n(pmt) $ python -m pytest\r\n================================ test session starts =================================\r\nplatform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0\r\nrootdir: /tmp/pmt\r\ncollected 2 items \r\n\r\ntests/test_pmt.py .. [100%]\r\n\r\n================================= 2 passed in 0.01s ==================================\r\n```\r\nTo finally reproduce the behaviour:\r\n* open the source file with `vim /tmp/pmt/src/pmt/spam.py`\r\n* move the cursor to `spamfunc`\r\n* start function renaming by hitting `\u003cC-c>rr`\r\n* insert a different name, for instance `hamfunc` and press `\u003cEnter>`\r\n* perform the renaming by inserting `1\u003cEnter>`\r\n\r\nAfter that, the renaming was successfully done in `/tmp/pmt/src/pmt/spam.py` and `/tmp/pmt/src/pmt/bacon.py` _but not in_ `tmp/pmt/tests/test_pmt.py` (as I expect).\r\n\r\n### What I have tried\r\nI tried to add manually the `tests` directory to the `.ropeproject/config.py` file\r\n```python\r\ndef set_prefs(prefs):\r\n # … more code of the default config.py file …\r\n\r\n # Custom source folders: By default rope searches the project\r\n # for finding source folders (folders that should be searched\r\n # for finding modules). You can add paths to that list. Note\r\n # that rope guesses project source folders correctly most of the\r\n # time; use this if you have any problems.\r\n # The folders should be relative to project root and use '/' for\r\n # separating folders regardless of the platform rope is running on.\r\n # 'src/my_source_folder' for instance.\r\n prefs.add('source_folders', 'tests')\r\n\r\n # … more code of the default config.py file …\r\n```\r\nwith no success.\r\n\r\nWhen I change the import policy by\r\n* uninstalling the module again with `(pmt) $ python -m pip uninstall pmt`\r\n* change the imports of `tmp/pmt/tests/test_pmt.py` to\r\n ```python\r\n from src.pmt.bacon import baconfunc\r\n from src.pmt.spam import spamfunc\r\n ```\r\n\r\nthen the renaming as suggested above _does work_, but that project structure is _not_ as I or the `pytest` guys, respectively, want it to be.\r\n\r\n### Used versions\r\n```bash\r\n(pmt) $ python --version\r\nPython 3.10.6\r\n(pmt) $ python -m pip freeze | grep 'build\\|pytest'\r\nbuild==0.8.0\r\npytest==7.1.3\r\n```\r\n\r\nPymode version: `commit 85d2cd1a196ac1def79d4599b5be69395ed5b603 (HEAD → develop)`","author":{"url":"https://github.com/claudio-ebel","@type":"Person","name":"claudio-ebel"},"datePublished":"2022-09-06T23:02:13Z","url":"https://github.com/python-mode/python-mode/issues/1159"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6f7056f1-a37f-062e-3fed-0b4d750f8d63 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D92:3D4084:520091:6BAAC2:6AFE66D3 |
| html-safe-nonce | 9c0020a892ed1f0f3c3cbfcbdef057aa824579c6c42484c977e2d64082bb3740 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDkyOjNENDA4NDo1MjAwOTE6NkJBQUMyOjZBRkU2NkQzIiwidmlzaXRvcl9pZCI6IjE4Njg4MTE3MzYyNDU0OTU1MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 32ba63a7f7b52de0bf784bbeb1a80cf9b2145ac5d7c30c6c6343b0de35384b99 |
| hovercard-subject-tag | issue:1363897855 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-mode/python-mode/1159/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4aa5357a34b3bbce2609e9aa598b1a694b107fcfecacc857d24ba3a936726991/python-mode/python-mode/issues/1159 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4aa5357a34b3bbce2609e9aa598b1a694b107fcfecacc857d24ba3a936726991/python-mode/python-mode/issues/1159 |
| og:image:alt | Using the python project scheme suggested by the pytest documentation, pymode does not include the tests/ directory into its ropeproject when the “include method” of the src/ directory is done via ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | claudio-ebel |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-mode/python-mode git https://github.com/python-mode/python-mode.git |
| octolytics-dimension-user_id | 13965098 |
| octolytics-dimension-user_login | python-mode |
| octolytics-dimension-repository_id | 2408911 |
| octolytics-dimension-repository_nwo | python-mode/python-mode |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2408911 |
| octolytics-dimension-repository_network_root_nwo | python-mode/python-mode |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width