Giter VIP home page Giter VIP logo

testing-mwe-pytest-in-package's People

Contributors

epogrebnyak avatar gabrielelanaro avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

gitter-badger

testing-mwe-pytest-in-package's Issues

Py.test and module inside a package

Following Gabriele suggestions I made a structrue in setting_4 that has a package called pkg and test folder in it.

test\test_in_sister_fodler.py has:

from ..pkg import code3

def test_foo():
   assert code3.foo() == 1
   print ("Test OK.")

I'm in root of this repo and I run python -m setting_4.test.test_in_sister_folder or https://github.com/epogrebnyak/mwe-pytest-in-package/blob/master/run_test_setting_4.bat on Windows and it works.

My problem is that now py.test started from this root folder (and also from elsewhere) fails with:

__________ ERROR collecting setting_4/test/test_in_sister_folder.py ___________
setting_4\test\test_in_sister_folder.py:1: in <module>
    from ..pkg import code3
E   ValueError: attempted relative import beyond top-level package

Isn't that sad? I need a solution where I can both run

  • py.test
  • standalone module inside a package.

Setting 3 and 4

I basically try to replicate a setting from https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules where tests are stored in a child (setting 3) or sister (setting 4) fodler relative to the script.

I have not done pip install -e or any other command to register the package, that can be the reason. I do not understand what happens then and want stay wasy from it, if I can.

My intended result is to store tests in child or sister forlder and to be able to import a function from code3.py module with least extra settings (package setup, pythonpath, etc).

Need some changes in these lines of code and or some other action:

Also may help adding init.py to test folder, even though this is not encouraged in https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules

workflow bestpractice comment needed?

A follow-up when people arrannge code into package, how they work on running it in due course of programming? In an IDE like Spyder (Anaconda native IDE) seems ther is now way to run a module inside a package. To people keep running python -m setting_4.test.test_in_sister_folder or other python -m from cli? Or write code not a package first and do not modify it once it becomes a pakage? What is you typical procedure?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.